C Interview Questions and Answers

Hi Programmers, welcome to Ozanecare. In this article , i’ll important tricky C Program interview Question and Answer with detail explanation.

Question 1 :

Correct Answer C.
Code Explanation :
step 1 : if you debug/run the program then control goes to main method thereafter that go inside of the main.
step 2 : i have taken one integer types variable i.
step 3 : next control goes to for loop, i = 5, condition check , 5 > 1 (true) thereafter control go to ; (semicolon).
step 4 : Semicolon(;) in C language called line terminator character. its able to break any statement.
step 5 : since for loop condition true so loop continue.next iteration i become 5,next 4 next 3, next 2.

step 6 : when i = 1 then check condition 1 > 1 , condition false then it terminate the loop.
step 7 : control go to printf method and display i value.
So , finally output display 1

Question 2 :

Code Explanation :
step 1 : if you debug/run the program then control goes to main function thereafter that go inside of the main.
step 2 : i have taken one integer types variable i.
step 3 : next control goes to while loop, i = 5, condition check , 5 > 1 (true) thereafter control go to ; (semicolon).
step 4 : Semicolon(;) in c called line terminator character. its able to break any statement.
step 5 : since while loop condition true so loop continue. i– so ,next iteration i become 5,4,3,2.
step 6 : when i = 1 then check condition 1 > 1 , condition false then it terminate the loop and it also decrease i value because
post decrement(i–).
step 7 : i become 0 and hereafter control go to printf function and display i value. So , finally output display 0. correct answer B.

Question 3 :

Code Explanation :
step 1 : if you debug/run the program then control goes to main function thereafter that go inside of the main.
step 2 : i have taken one integer types variable i.
step 3 : next control go to while loop, i = 1, condition check , 1 < 11 – 3 = (true) thereafter control go to ; (semicolon).
step 4 : Semicolon(;) in c called line terminator character. its able to break any statement.
step 5 : since while loop condition true so loop continue. i++ , ++i so ,next iteration i become 5 , 7 .
step 6 : when i = 7 then check condition 7 < 11 – 9 , condition false then it terminate the loop .
So , finally output display 7.Correct Answer A.

Question 4 :

I have taken char type variable c and initialize with p.
for( ; ; ) it means for loop continue on.
int i = c + 9 or int i = ‘p’ + 9.
the ASCII value of p = 112.
int i = 112 + 9 = 121. so ,correct output D. None of these.

Question 5 :

Code Explanation :
step 1 : if you debug/run the program then control goes to main function thereafter that go inside of the main. step 2 : i have taken one integer types variable i and i initialize with 10.
step 3 : next control go to for loop, for loop syntax :
for(initialize ; condition ; increment/decrement) step 4 : Semicolon(;) in c called line terminator character. its able to break any statement.
step 5 : for loop condition remain true because condition part blank. step 6 : next control go inside of for loop and there that find printf function so it will print i value.
step 7 : and for loop continue on when control goes to
else part then terminate loop because else body part has break statement.
so output display… 10 6 2 -2 -6 -10 -14
Correct Answer D.

Question 6 :

Correct Answer B.
Code Explanation :
step 1 : if you debug/run the program then control goes to main method thereafter that go inside of the main.
step 2 : i have taken one integer types variable i and i initialize with 0.
step 3 : next control go to for loop, for loop syntax :
for(initialize ; condition ; increment/decrement)
step 4 : Semicolon(;) in c called line terminator character. its able to break any statement.
step 5 : in for loop i = 0 , 0 < 10 (true) then it goes to inside of for loop
step 7 : 0 concatenate with space character. ASCII of space 32 and 32 + 0 =32 on next iteration i = 1 and 1 + 32 = 33 like this loop continue.
step 8 : so , final output display 32333435363738394041.
when i = 10 then 10 < 10 condition false and it terminate loop.

Question 7 :

Code Explanation :
step 1 : if you debug the program then control goes to Main method thereafter that go inside of the Main.
step 2 : i have taken two integer types variable i=1,j=1
step 3 : for(–i && ++j ; i<10 ; ++i) (++i pre-increment it means first increase i value),(i++ post-increment it means first initialize/read value then increase). i– post-decrement it means first initialize/read value then decrease.
step 4 : i = 1 , j =1 ; for(–i && ++j ; i<10 ; ++i) –1 && ++1 or 0 && 2 = 0 check condition 0<10 true , printf (“%d”,++i) print 1, next ++i , i=2,++i =3 print 3 ++4, 4 < 10 true ,++i =5 print 5 , ++i = 6 6<10 true ++i =7 ++i = 8 and 8<10 true ++i =9 print 9 ,++i = 10 , 10<10 false .loop terminate. step 5 : so ,finally output display 1 3 5 7 9

Question 8 :

Correct Answer D.
Code Explanation :
step 1 : if you debug the program then control goes to Main method thereafter that go inside of the Main.
step 2 : i have taken two integer types variable i=2,k.
step 3 : ++i , i++ , i–; (++i pre-increment it means first increase i value),(i++ post-increment it means first initialize/read value then increase). i– post-decrement it means first initialize/read value then decrease. step 4 : k = i++ + i– + ++i; 2++ +3– + 3 = 8
step 5 : so , k=8 , final output 3,8.

Question 9 :

Code Explanation : If statement return true so If(1) and function only takes one parameter. so it comes Yes and others parameter ignore. The next printf will only print Martin because initial character was incremented from 3. so correct output D. Yes Martin.

Question 10 :

Code Details : Correct Answer NaN. because float and double data type values are not same. float takes 4 bytes and double takes 8 bytes.

Post Author: adama