C | Operators | Question 27

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
   int a = 0;
   int b;
   a = (a == (a == 1));
   printf("%d", a);
   return 0;
}

chevron_right


(A) 0
(B) 1
(C) Big negative number
(D) -1


Answer: (B)

Explanation: We need to figure out value of “(a == (a == 1))”



(a == 1) returns false as a is initialized as 0. So in outer bracket, false is compared with a. Since a is 0, result of of outer bracket becomes true.



The important thing to note is, in C, when a boolean value is compared or assigned to an integer value, false is considered as 0 and true is considered as 1.

Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : nidhi_biet



Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.