C interview Question

Document Sample
C interview  Question Powered By Docstoc
					Question: What is static variable?

Ans. Static variable is a variable that has visibility of a local variable and life time
of an external variable. It is stored in main memory and has default value zero.

Question: Where are the auto variables stored?

Ans: Auto variables are stored in main memory and their default value is a
garbage value.

Question: Where does global, static, local, register variables and C
Program instructions get stored?

Ans: Global , static, local : In main memory                    Register variable: In
registers C        program        :       In                   main         memory.

Question: Why Preincrement operator is faster than Postincrement?

Ans: Evaluation of any expression is from left to right. Preincrement is faster
because it doesn't need to save the current value for next instruction whereas
Postincrement needs to saves current value to be incremented after execution of
current instruction.

Question: In header files whether functions are declared or defined?

Ans: Functions in header file are declared.

Question: Difference between arrays and linked list?

Ans: Major differences between arrays and linked lists are: (i) In array
consecutive elements are stored in consecutive memory locations whereas in
linked list it not so. (ii) In array address of next element is consecutive and
whereas in linked list it is specified in the address part of each node.(iii) Linked
List makes better use of memory than arrays.(iv) Insertion or deletion of an
element in array is difficult than insertion or deletion in linked list.

Question: What is the use of typedef?

Ans: Major uses of typedef are:
(i) It increases the portability.

(ii) It simplify the complex declaration and improve readability of the program.

Question: What are the differences between malloc() and calloc()?

Ans: A malloc( ) function allocates a block of memory of the specified size and
returns a pointer of specified data type whereas a calloc( ) function allocates a
space for an array of elements , initializes them to zero and then returns a pointer
to the memory.

Question: What are the advantages of using pointers in a program?

Ans: Major advantages of pointers are:

(i) It allows management of structures which are allocated memory dynamically.

(ii) It allows passing of arrays and strings to functions more efficiently.

(iii) It makes possible to pass address of structure instead of entire structure to
the functions.

(iv) It makes possible to return more than one value from the function.

Question: What do the ‘c’ and ‘v’ in argc and argv stand for?

Ans: c stands for counter and v stands for vector.

Question: Is function declarations are used only for compilation and not
get stored in the .EXE File ?

Ans : Yes

Question: Are the variables argc and argv are local to main?

Ans: Yes

   1.   What value of c will get printed


         int a, b, c;

         a = 10;

         b = 20;

         c = printf(“%d”,a) + ++b;

         printf (“%d”,c);


a. 23                                b. 22

c. 30                                d. Compilation Error

Answer: a

Explanation: printf() will return no. of bytes it printed.

Expression becomes

        c = 2 + ++b;

then value of b is incremented before addition.

2. How many times the below loop will get executed?



          int i;

         for (i=9 ; i ; i=i-2)




a. 5                                  b. 6

c. Compilation Error                     d. Infinite

Answer: d

Explanation : Above loop will iterate till i have non zero value. Initial value
of i is 9 and it get decremented by 2 in every iteration ( 9, 7, 5, 3, 1, -1, -3
….). Value of i will never become 0 and loop will run infinitely.

3. What will be the output



    int i;

    i = 10;


    printf(“%d”, i , i++);


a. 5          11          b. 6   10

c. 5          10          d. 6   11

Answer: a

Explanation: Value in a function get passed from right to left. First i++ get
passed and it make i = 11.
4. What the below statement will print if a=10 and b = 20?

printf(“ %d”,a==b);

a. 20                          b. 0

c. 10                         c. 1

Answer: b

Explanation: a==b is a expression and will return 1 (true) or 0 (False)
depending on the values of a and b. Here a and b are not equal so 0 is

5. What the below statement will print if a=10?

printf(“ %d %d”,a, !a++);

a. 11     0                    b. 10   10

c. 10     0                   d. 0     10

Answer: a

Explanation: Values in the function get passed from right to left. First !a++
get processed which pass zero as argument and make a equal to 11.

6. What will be the output



        int i;
       i =10;

       if (i ==20 || 30)









a. True                         b. False

c. Syntax error                  d. Run time Error

Answer : a

Explanation: i==20 is a expression which will return TRUE or FALSE
depending on the value of i. In this program it will return 0 so the statement

                If ( 0 || 30)

30 is a nonzero value which means TRUE (1) in C when ORed with 0 will
result TRUE.

7. What will be the output of the following program?




a. Compilation Error                     b. G

c. t                               d n

Answer: c

Explanation: Gyantonic is a constant string and character at index 4 will
get printed.

8. What will be the output



            if (1,0)








a. True                b. False

c. Compilation error     d. Run time Error

Answer : b

Explanation : comma(,) operator returns the value which at the right hand
side of , . if statement become if(0)

Shared By:
Description: interview Question,