edited by
500 views
0 votes
0 votes
#include<stdio.h>
int main()
{
   printf("%d\n",1==5==5);
   printf("%d\n",1==5!=5);
   printf("%d\n",1!=5!=5);
   printf("%d\n",1!=5==5);
   return 0; 
}

What is the output?

edited by

1 Answer

Best answer
4 votes
4 votes
Associativity of '==' and '!=' is left-right

 1==5==5 will be solved as-

(1==5)==5         

0==5           ('==' returns 0 to denote false)

0      [printf prints the number as it is]
   
1==5!=5 will be solved as-

(1==5)!=5

0!=5

1

Similarly, 1!=5!=5 will o/p 1 and 1!=5==5 gives o/p 0.
selected by

Related questions