Question discussion

What is the output of the following C program?#include int main() { int x = 29; printf("%d %d %d", x & (x - 1), x | 3, x ^ x >> 2); return…

925Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int x = 29;
    printf("%d %d %d", x & (x - 1), x | 3, x ^ x >> 2);
    return 0;
}
  • A28 31 26
  • B28 29 26
  • C27 31 24
  • D28 31 23
Correct answer: A

Explanation

29 & 28 = 28; 29 | 3 = 31; since >> binds tighter than ^, x ^ (x >> 2) = 29 ^ 7 = 26.

Discussion 0

Nobody has replied yet. Start the discussion!