ProgrammingModerateProduct-company MCQ pattern
On a two's-complement machine, what is printed?
On a two's-complement machine, what is printed?
printf("%d %d", 40 & -40, 40 & (40 - 1));- A. 32 8
- B. 40 0
- C. 8 39
- D. 8 32
Correct answer: D. 8 32
40 = 101000. -40 is ~40 + 1, which keeps only the lowest set bit in common: 40 & -40 = 1000 = 8. 40 & 39 = 101000 & 100111 = 100000 = 32, which clears the lowest set bit.
More C Programming questions
- For a signed int n on a two's-complement machine, how many of these are correct? (i) (n & (n - 1)) == 0 is true for every positive power…
- What is printed? c #define DOUBLE(x) x + x printf("%d", 10 / DOUBLE(5) 2);
- Which of a, b, c, d are pointers? c #define IPTR int typedef int IPT; IPTR a, b; IPT c, d;
- What is printed? c #define DEBUG 0 ... #ifdef DEBUG printf("on "); #endif #if DEBUG printf("trace"); #endif
- In C, with int i = 1, a[5];, which statement has undefined behaviour?
- Compiled as C with 4-byte int, what is printed? c printf("%zu %zu", sizeof('A'), sizeof(char));