ProgrammingModerateHCL · Tech Mahindra pattern
What is printed on a two's-complement machine?
What is printed on a two's-complement machine?
printf("%d", ~5);- A. -5
- B. 250
- C. 10
- D. -6
Correct answer: D. -6
~ flips every bit. In two's complement ~x = -x - 1, so ~5 = -6. 250 is what you would get if only 8 bits were flipped and read as unsigned.
More C Programming questions
- What is printed by a C99 (or later) compiler? c printf("%d %d", -7 / 2, -7 % 2);
- What is printed? c char s = "Campus"; printf("%c%s", (s + 1), s + 4);
- What is printed? c printf("%d", printf("hello"));
- On a 64-bit system (8-byte pointers, 4-byte int), what does f print? c void f(int a[10]) { printf("%zu", sizeof(a)); }
- How many times is fib called in total (including the first call) when evaluating fib(5)? c int fib(int n) { if (n <= 1) return n; return…
- What is printed? c int x = 181, c = 0; while (x) { x &= x - 1; c++; } printf("%d", c);