Home Interview Questions and AnswersTechnical Interview Questions and AnswersC Programming C Programming Interview Questions and Answers For Freshers Part-1

c program1.What is a pointer on pointer?
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.

2.Distinguish between malloc() & calloc() memory allocation.
Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.

3.What is keyword auto for?
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.

4.What are the valid places for the keyword break to appear.
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.

5.Explain the syntax for for loop.
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.

6.What is difference between including the header file with-in angular braces < > and double quotes “ “
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.

7.How a negative integer is stored.
Get the two’s compliment of the same positive integer. Eg: 1101 (-5)

Step-1 − One’s compliment of 5 : 1010

Step-2 − Add 1 to above, giving 1011, which is -5

8.What is a static variable?
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.

9.What is a NULL pointer?
A pointer pointing to nothing is called so. Eg: char *p=NULL;

10.What is the purpose of extern storage specifier?
Used to resolve the scope of global symbol.

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

int i = 20;

You may also like

Leave a Comment