Question for Campus Preparation

What will be the output ?

#include<stdio.h>

int main()

{

int x=5;

if(x>3>2)

printf(“Hello %d”,x);

else

printf(“Hi %d”,x);

}

ANS:  Hi 5

Explanation:  Here inside if we have written x>3>2 i.e 5>3>2  .In it 2 operators are there and both are same so they are of same priority so question comes which one should get evaluated first .In case of same precedence operators we solve the expression from left to right so first 5>3 will be evaluated which is true so finally our expression will become 1>2 as true means 1 and false means 0.Now this final expression will be evaluated and it will give you result as false.

 

Please follow and like us:
This entry was posted in Campus Preparation and tagged , , , , . Bookmark the permalink.

Leave a Reply

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