Multiple choice

What is the output of the given program?

int main()
 {
 int x = 24;
 int y = 42;
 printf("%d",(~x) | (~y) );
 }

    • 25
    • 43
    • 9
    • 6
  1. Compiler error

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

This is the correct answer. The compiler will first reverse the bits of  x and y as we have used ~ (tilde) operator on them. So, the expression becomes: -24 | -43. Now, the compiler will convert -25 and -43 into binary and perform OR operation on them. So, the answer will be -9.