Sunday , December 11 2016
Home / C Interview Questions

C Interview Questions

 

 best selected c interview questions and answers which you may have not come across until now. If you consider yourself as an excellent programmer than here are some mind exploding tricks and interview questions that are practically sound to a regular c programmer.

 

 

Question 1  

What is the output:

 

Answer

 Compilation Error; L value required as left operand of assignment.
(NO operations can be performed on the left side of assignment operator ) and a++ means a=a+1;

Question 2

What is the output :

Answer

 2 2 1
Here in structure code the width of the variables that is how many bits can they hold are initialise i.e. x can hold three bits, y also 3 bits and z only 2 bits. Value passed by the structure variable is x=2 = 010 and as mentioned x can hold upto 3 bits so 1st bit is zero means positive and next two bits are 10 = 2(in decimal) so get.x = 2;

Similarly , y holds 3 bits as declared in structure but value passed is y=-6 = 2’s complement of 110 = 010 ; MSB is zero means +ve and next two bits are 10 = 2 so get.y=2 ;
Similarly, z holds 2 bits as declared in strucuture but value passed is z=5=101,but it will take only upto two bits i.e. 01 where MSB is 0 means +ve and binary for 1 = 1 so get.z=1;

Question 3

What is the output:

 

Answer

6
++a means a=a+1 so a=6; !a = 0 [ since !zero =1 and !nonzero = 0] then 6 +0 = 6;

Question 4

What is the output:

 

Answer

 131
015(Octal number)(16 bit representation)-0000000000001101
0x71(Hex):0000000001110001
5(dec):0000000000000101
binary addition of all :0000000010000011=131

Question 5

What is the output :

 

Answer

 s = 2
[the answer above is correct don’t comment – “your answers are wrong” Go for the explanation below]

When parameters are passed to the predefined function printf in c library the first parameter is the string and second one is the variable.

Here ,  when the string is send along with the pointer position +2 i.e. the now the string that will be read will be from the second position.
So as index starts from 0 second position will be s = %d and %d=a=2 so:  s = 2
Ans = %d
01234567

Question 6

What is the output :

 

Answer

 It is equal

Note: Attempt next question 

Question 7

What is the output :

 

Answer

 It is not equal
Explanation:  2==2 will evaluate to 1(true) and then 1==2 will evaluate to 0(false) so It is not equal will be printed.

 

Question 8

 What “condition” expression can be used so that the following code snippet will print Hello world !

 

Answer

 Ans: !printf(“Hello”)
Explanation:  if(!printf(“Hello”)) executes and Hello is printed as soon as printf is called then printf returns 5 (number of characters it has printed) and we all know !5 = 0 ;  means False ; so else part will execute and print World ! .. Hence the output Hello World !

 

 

 Incoming terms: C interview questions and answers

2 comments

  1. hiii,i want to learn c interview question

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.