Question discussion

What is the output of the following C program?#include int main() { int x = 5; printf("%d %d", x > 1, ~x & 0xF); return 0; }

1931Medium 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 = 5;
    printf("%d %d", x << 2 >> 1, ~x & 0xF);
    return 0;
}
  • A5 10
  • B10 6
  • C20 10
  • D10 10
Correct answer: D

Explanation

x << 2 is 20 and 20 >> 1 is 10; ~5 is −6 whose low four bits are 1010, so ~x & 0xF is 10.

Discussion 0

Nobody has replied yet. Start the discussion!