C | Operators | Question 26

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A) 0
(B) 1
(C) A bog negative Number
(D) Compiler Error


Answer: (A)

Explanation: The important thing to note here is ~ is a bitwise not operator. So the value of ~0 would be all 1s in binary representation which means decimal value of ~0 is not 1. Therefore the result of comparison operator becomes 0.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


1


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