C Interview Questions

C interview questions are given with the answers in this website. We have given C interview questions faced by freshers and experienced in real interviews in IT industries. Users are welcome to suggest or add any other questions and answers related to C interview questions. Click on each question below to get the answers.

Question-1. What is a pointer on pointer ?

Answer- It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable.

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.

Question-2. Distinguish between malloc() & calloc() memory allocation ?

Answer- Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.

 

Question-3. What is keyword auto for ?

Answer- By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables.

void f() {
   int i;
   auto int j;
}

NOTE − A global variable can’t be an automatic variable.

Question-4. What are the valid places for the keyword break to appear ?

Answer- Break can appear only with in the looping control and switch statement. The purpose of the break is to bring the control out from the said blocks.

 

Question-5. Explain the syntax for for loop ?

Answer-

for(expression-1;expression-2;expression-3) {
   //set of statements
}

When control reaches for expression-1 is executed first. Then following expression-2, and if expression-2 evaluates to non-zero ‘set of statements’ and expression-3 is executed, follows expression-2.

Question-6. What is difference between including the header file with-in angular braces < > and double quotes “ “ ?

Answer- If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in “ “, then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path.

 

Question-7. How a negative integer is stored ?

Answer- Get the two’s compliment of the same positive integer. Eg: 1011 (-5)

Step-1 − One’s compliment of 5 : 1010
Step-2 − Add 1 to above, giving 1011, which is -5

 

Question-8. What is a static variable ?

Answer- A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice.

void f() { 
   static int i; 
   ++i; 
   printf(“%d “,i); 
}

If a global variable is static then its visibility is limited to the same source code.

Question-9. What is a NULL pointer ?

Answer- A pointer pointing to nothing is called so. Eg: char *p=NULL;

 

Question-10. What is the purpose of extern storage specifier?

Answer- Used to resolve the scope of global symbol.

Eg:

main() {
   extern int i;
   Printf(“%d”,i);
}

int i = 20;