C Programs Interview Questions and Answers with Explanations:
C Interview Questions Programs with Solutions
This is the post full of problems….. Yes, this is an exercise, you have to solve your own and find the output of the programs give below.
Following are the set of C programs. Just try to find the output for them on your own, then check for answers.
Nowadays, in many interviews you can find such programs asked to know your technical skill.
You may also take this as such a test. Lets Test Your Technical and Programming Knowledge……….
Interview Questions C Programs Solved:
[Question – 1]
printf(“%d %d %c”,3200,ch,ch);
ANSWER: 3200 291 #
For first variable the value displayed as it is : 3200
For next %d, the character is converted to integer 291 is displayed.
for last %c the character equal to 291 # is displayed.
[Question – 2]
a=-3 – -3;
b=-3 – -(-3);
printf(“a=%d b=%d b=%d”, a, b);
ANSWER: a=0 b=- 6
For a=%d, the value of a (-3 – -3) = -3+3 =0 is displayed.
For b=%d, the value of b (-3 – – (-3)) = -3-3 = -6 is displayed.
For the last b=%d, the value of nothing is specified. Hence ignored. The final output will be a=0, b=-6.
[Question – 3]
The value of x= 3*4%5 = 12 %(mod) 5= remainder 2; x=2;
Here as per operator precedence, both * and % have equal precedence. As we have higher preference from left to right.
Hence * (multiplication) is done at first , then modulo operation is performed.
[Question – 4]
ANSWER: Error Message : Illegal use of floating point in function main
c=5/2 = 0.5. Here the float value cannot be converted into int without any explicit information.
Hence error message will be the output.
[Question – 5]
int x=10, y=5, i,j;
printf(“i =%d, j=%d”, i,j);
ANSWER: i=1 j=1
i= x> 9 = 10>9 = true. Hence output i=1 (the value of true is 1; false is 0;)
j= x>3 && y!=3 = 10(the value of x) > 3 && (AND condition: both conditions must true) 5(the value of y) not equals to 3.
Here both conditions are true . So the output also true: the output i=1 and j=1.
[Question – 6]
int a=100, b=200;
c= (a= = 100 || b>200);
c= (a == 100 || b>200)
Here || is an OR condition symbol which means if either one of the condition is true then the answer is true.
Now c = (100[the value of a] = 100 is true; 200[the value of b] > 200 is false). As per OR condition, the output is TRUE: 1.
[Question – 7]
int a=300, b= 10, c=20;
ANSWER: b=300, c=200
In the condition (!a>=400), ‘!’ means NOT condition. Here the condition: ( 300 (the value of a) is not greater than 400) is true.
Hence the printf statement displayed: b = 300 and c = 200.
Here, even though the value of b and c is declared before if condition, it won’t taken into consideration. Because, the if condition is true.
If the if condition is false, then the values of b will 10 and c will be 20.
[Question – 8]
printf(“Its not the pie value”);
printf(“It is the pie value”);
ANSWER: It is the pie value
Here the if condition itself can’t check. Hence, the else part will be taken into account.
The output will be the else part printf statement: ” It is the pie value”.
[Question – 9]
float a=12.25, b= 13.65;
printf(“a and b are equal”);
printf(“a and b are not equal”);
ANSWER: a and b are equal
Here, the if condition: (a = =b) : (12.25 = = 13.65) is not true.
Hence the output will be the else part output statement: a and b are not equal.
[Question – 10]
int i=10, j=40;
if(((j-i) % 10) = = 3 )
printf(“The right program”);
printf(“The Wrong program”);
ANSWER: The wrong program.
Here the if condition: (((j-i) % 10)=3) : (30%10)=3 is false.
Hence the output will be the printf of else part: “The Wrong Program”.
Thanks for reading about C Programming Interview Questions and Answers with Explanations