ExamVeda
Login
Home
Operators and Expressions
?

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);
}

Answer & Solution
Correct Answer: Option D
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

6 Comments
Test Mail
Test Mail 4 years ago
int a,b=7;
if(b1;
else
a=a;
}
Sudheer Sudheer
Sudheer Sudheer 6 years ago
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;
}
}
Ajinkya Londhe
Ajinkya Londhe 9 years ago
33
Vishwajeet Fartade
Vishwajeet Fartade 9 years ago
ok
Ramachandran Pillai
Ramachandran Pillai 10 years ago
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
Rohit Raina
Rohit Raina 10 years ago
how b will incremented?