Multiple choice technology programming languages

void main() { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); }

  1. not same

  2. same

  3. unknown symbol ‘~’

  4. none of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When -1 is assigned to an unsigned int, it wraps around to the maximum value (all bits set to 1). The bitwise NOT of 0 (~0) also produces all bits set to 1. Therefore, both x and y hold the same bit pattern and the comparison 'x == y' evaluates to true, printing 'same'.