
1 
What is the output of the following program?
#include<stdio.h>
void main()
{
int a=6,b=5,c=4;
printf("%d",(a>b>c?1:0));
} 

A. 
1 

B. 
0 

C. 
Error 

D. 
None of the Above 
See Answer & Explanation
Lets Discuss
Correct answer is : B
Explanation
Here, the expression a>b>c is evaluated as:
(a>b)>c
= (6>5)>4 which becomes 1>4 which is FALSE.
Hence the output is 0.
Now, a few lines about Ternary operator(?:)
Let us consider an expression
Result=(W>X) ? Y : Z,
If the expression (W>X)is TRUE then the Result = Y else Result = Z.
2 
What is the output of the following program?
#include<stdio.h>
void main()
{
printf("32%5=%d",32%5);
printf("\n32%5=%d",32%5);
printf("\n32%5=%d",32%5);
printf("\n32%5=%d",32%5);
} 

A. 
32%5=2
32%5=2
32%5=2
32%5=2 

B. 
32%5=2
32%5=2
32%5=2
32%5=2 

C. 
32%5=2
32%5=2
32%5=2
32%5=2 

D. 
32%5=2
32%5=3
32%5=2
32%5=2 
See Answer & Explanation
Lets Discuss
Correct answer is : A
Explanation In C , when you use modulus operator and the operands are signed values,
The signs are ignored while evaluating the remainder and then after getting the remainder, the sign of the numerator is assigned to the remainder.
Hence, 32%5 is 2 and 32%5 is also 2 , as the sign of numerator(32) is ve.
In case of 32%5 the answer is +2 because the 32 is a +ve number even though the denominator is ve.
3 
What is the output of the following program?
#include<stdio.h>
void main()
{
float f=0.1;
char c='a';
double d=0.456;
f++;
c++;
d++;
printf("%f %c %f\n",f,c,d);
} 

A. 
0.2 b 0.556 

B. 
1.1 b 1.456 

C. 
1.100000 b 1.456000 

D. 
Compilation Error: Increment operator can not be used with these data types. 
See Answer & Explanation
Lets Discuss
Correct answer is : C
Explanation
Increment operator works perfectly with float, double and char data types.
Increment operator simply means increment by 1.(Except in the case of pointers, where it increments my the size of datatype pointed by the pointer)
Hence, 0.1 became 1.1 and since we know that when a float is printed there should be six digits after the decimal, Hence
1.100000 is printed.
Same is the case with variable of "double" datatype, So, 1.456000 is printed.
A character is nothing but an ASCII code. Hence , 'a' whose ASCII code is 97 incremented by 1
and becomes 98 which is the ASCII code for 'b'. The format specifier is %c so the character 'b' is printed.
4 
What is the output of the following program?
#include<stdio.h>
int main()
{
int a=2;
a=a+2<<1;
printf("%d ",a);
a=a+(2<<1);
printf("%d",a);
} 

A. 
8 8 

B. 
8 12 

C. 
6 6 

D. 
2 3 
See Answer & Explanation
Lets Discuss
Correct answer is : B
Explanation
The precedence of + is more than << (left shift operator).
Consider the expression: a=a+2<<1;
Hence , the above expression is (a+2)<<1
4<<1
i.e. 8 (Left Shift Doubles the value)
Now, a=8
In the second statement: a=a+(2<<1)
The Left shift operator executes before, So a=a+4= 8+4=12
Hence the answer is 8 12


