RUN


Q1. What is the difference between int main() Vs void main() Vs int main(void) in C ?

Ans. void main() – void‘ is the return type of the function. void means null in C. Hence the function does not return any value to the Operating system after its execution, that is on exit.

int main() –  The return type of main is int. That is the function ideally expects a return type value int (integer) to be passed to it. Hence, the return statement; which returns value 0 to main on completion of the program.

int main(void) – This is similar to int main(), with only one change –  the number of arguments that can be passed is now null to main.

Hence when your main function is not taking any argument, it is preferable to use int main(void). Read More…


Q2. What is the difference between Typeconversion and Typecasting in C ?

Ans. Type-conversion and Typecasting means conversion of value of an identifier/variable from one data type to another either implicitly that is automatically by C and explicitly that is forced conversion. Read More…


Q3. What is malloc, calloc, free, realloc ?

Ans. 

malloc() Allocates requested size of bytes and returns a pointer (void*) to memory
calloc() Allocates space for array elements, initializes to zero and then returns a pointer to the memory
free() De-allocates the previously allocated space
realloc() Changes the size of previously allocated space

Read More…


Q4. Difference between Recursion and Iteration in C ?

Ans.  Recursion is applied to functions, where the function calls itself to repeat the lines of code/ certain statements.

Iteration on the other hand, uses looping in order to execute a set of statements multiple times. A given problem can be solved both by recursion as well as iteration, however, they have certain important differences as well.

Read More…


Q5. Why do we need pointers in C ?

Ans. – To allocate memory dynamically.
– To refer to the same space in memory from multiple locations. This means that if you update the memory in one location, then that change can also be seen from another location in your code . Read More…


Q6. Difference Between C and C++ ?

Ans. To be specific C is the subset of C++ and C++ is the super-set of C.

It means most of the codes of C, can be run in C++, but not all the codes of C++ can be executed in C. Read More…


Q7. Difference Between Union and Structure ?

Ans. Structures and unions are a user-defined data type, also called as derived data type in C. These user-defined types gives us the flexibility to store values belonging to different data types under a single entity. They serve as a collection of different data types which are members of a particular group. Read More…


Q8. Difference between Call by Value Vs Call by Reference ?

Ans. Call by Value – This method uses inner mode semantics. Inner mode semantics means that when we make any changes in the initial parameter, then it doesn’t get reflected in the called parameter.

Call by Reference – This method uses inner & outer both mode of semantics. In this method, changes made to the initial parameter gets reflected back to the caller through parameter passing.

Read More…


Q9. Can we Compile a C program without header file ?

Ans. Yes.

//Declare the printf() function
  int printf(const char *format, ...);
  int main()
  {
  printf( "Hello StudyMite !" );
  return 0;
  }

Read More…


Q10. What is NULL pointer ?

Ans. A null pointer points to nothing. It is assigned the value NULL, therefore it is called the null pointer.
If you do not want the pointer to store any address then assign it to NULL. Read More…


Q11. What is void pointer ?

Ans. A void pointer is a pointer that has no specific data type associated with it. Therefore, it can point to a variable of any data type. Void pointers are valid in C. Read More…


Q12. What is Dangling pointer ?

Ans. A dangling pointer points to a non-existent memory location. This pointer points to a memory location that has been freed. Dangling pointers arise when an object is deleted or de-allocated without modifying the value of the pointer. Since the value of the pointer is not modified, it still points to the memory location of the de-allocated memory. Read More…


Q13. What is wild and double pointer ?

Ans. Wild Pointer – If a pointer is not initialized to anything, not even NULL, is called a Wild Pointer. The pointer is assigned to a garbage value which may not even be a valid address. Such pointers point to some arbitrary memory location.

Double Pointer – A pointer to a pointer is called a double-pointer. Let’s say we have two pointers and a normal variable.
The first pointer stores the address of a variable. The second pointer, which is the double-pointer, stores the address of the first pointer. A double pointer is also known as pointer-to-pointer. Read More…


Q14. What is difference between i++ and ++i?

Ans. ++i will increment the value of i, and then return the incremented value.

i++ will increment the value of i, but return the original value that i held before being incremented.


Q15. What is modifier in C?

Ans. A modifier is used to alter the meaning of the base data type so that, the new data type thus generated can fit into the requirements in a better way.

The data type modifiers allowed in C are:

  • signed
  • unsigned
  • long
  • short

Q16. What is the difference between static & global variables?

Ans. Global Variable: Global variable is the variable that is declared outside of a block or function. These variables can be accessed from anywhere in the program.

Static Variable: The static variable retains its value between multiple function calls.


Q17.  What is Memory Leak in C?

Ans. A memory leak occurs when a memory that was previously allocated is not properly deallocated by the programmer.

void memoryLeakStudyMite( ){
    int *dataMem = new int;
    *dataMem = 100;
}

Q18. What is Static and Dynamic memory allocation?

Ans. Static memory allocation – 

  1. If Memory allocation is done before program execution, it is called static memory allocation.
  2. Also called as compile-time allocation as space allocation is done during compile time.
  3. When we know the size of variables, the size of array in advance then this type of allocation is useful.
  4. The memory allocated for such variables/array is from the stack area.

        Dynamic memory allocation – 

  1. If memory is allocated during run-time, this type of allocation is called dynamic memory allocation.
  2. It is a slow process as memory has to be allocated while programming execution.
  3. Usually, a programmer during compile time might not know the exact memory requirements for the program.
  4. Hence in such situations, memory is allocated while the program executes as per the need. Read More…

Q19. What is recursion in C?

Ans. Recursion or Circular Definition is a process in which a function calls itself directly or indirectly and the corresponding function is called recursive function. It is a technique wherein a function calls itself with a smaller part of the function/task in order to solve that problem. It is a process of defining something  in terms of itself. Read More…


Q20. What is pointer to pointer in C?

Ans. Let’s say we have two pointers and a normal variable. The first pointer stores the address of a variable. The second pointer, which is the double-pointer, stores the address of the first pointer. A double pointer is also known as pointer-to-pointer. Read More…


Q21. What is an auto keyword in C?

Ans. The auto keyword in C is used to declare a variable and the compiler will automatically figure out its type later.


Q22. Can we compile a program without main() function?

Ans. Yes.

#include<stdio.h>
#include<stdlib.h>
int studymite()
{
printf("Hallo World\n"); 
exit(0);
}

Q23. Program to Reverse String in C

Q24. Check if two strings are anagrams in C

Q25. Program to find Palindrome number in C

Q26. Prime number program

Q27. Reverse a Number Program

Q28. Pascal Triangle

Q29. Program in C to delete the vowels in a string


Q30. What is a C Token?

Ans. The smallest unit of a C program is known as a token. For example – variables, keywords, etc

Report Error/ Suggestion

Related Posts:




CopyRight © 2020

CopyRight © 2020