Determine output of the following program code.
#include<stdio.h>
void main()
{
int a, b=7;
a = b<4 ? b<<1 : ++b>4 ? 7>>1 : a;
printf("%d %d", a, b);
}
#include<stdio.h>
void main()
{
int a, b=7;
a = b<4 ? b<<1 : ++b>4 ? 7>>1 : a;
printf("%d %d", a, b);
}
A. 3 7
B. 7 3
C. 8 3
D. 3 8
E. None of these
Answer: Option D
Join The Discussion
Comments ( 6 )
Related Questions on Operators and Expressions
What does the ++ operator do in C when applied to a variable?
A. Decrements by 1
B. Adds 1
C. Doubles the value
D. Leaves it unchanged
int a,b=7;
if(b1;
else
a=a;
}
The Answer is a=3 and b=7.
Given Expression a = b1 : a;
We can write this in this format....
if ( b>1; // Do Right Shift Operation
} 7 = 0000 0111 need to add a bit ' 0 ' in the LeftMost.....
else Then 0000 0011 = 3 i.e a = 3.
{
a=a;
}
}
33
ok
The answer is :
7 false
So, executes ++b>4 ? 7>>1 : a
ie; 8>4 ? True .
So, a=7>>1
ie;
0111 is shifted right by one time
=> 0011 ie a=3
Thus, b=8 and a=3
how b will incremented?