ProgrammingVery hardProduct company OA
On a two's-complement machine, what is printed?
On a two's-complement machine, what is printed?
int x = 5;
printf("%d %d", -~x, ~-x);- A. 5 5
- B. 6 4
- C. 4 6
- D. 6 6
Correct answer: B. 6 4
In two's complement ~y = −y − 1. So −~x = −(−x − 1) = x + 1 = 6, and ~−x = x − 1 = 4. The operators apply right to left, innermost first.
More C Programming questions
- What is printed? c const char s = "ab cd"; printf("%zu", strlen(s));
- On an LP64 system (32-bit int, 64-bit long), what is printed? c printf("%zu %zu", sizeof(2147483647), sizeof(2147483648));
- What is printed? c printf("%d %d", '0', '0');
- What is printed? c printf("%d %d", !!"", !"");
- How many subsets does this code count? c int a[] = {2, 3, 5, 7, 8}, c = 0; for (int m = 0; m < 32; m++) { int s = 0; for (int i = 0; i <…
- What is the type of the result of subtracting two int pointers, p - q?