ProgrammingHardIBM · Deloitte pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int a = 6, b = 3;
printf("%d %d %d %d", a & b, a | b, a ^ b, ~a);- A. 2 7 5 -7
- B. 2 7 5 -6
- C. 3 7 5 -7
- D. 2 6 5 -7
Correct answer: A. 2 7 5 -7
6=0110, 3=0011. AND: 0010=2. OR: 0111=7. XOR: 0101=5. ~6 flips all bits of 0...0110, giving -7 in two's complement (since ~x = -x-1, so ~6 = -7).
More C Programming questions
- Assume 32-bit int. What is the value of n that checks whether the k-th bit (0-indexed from the LSB) of x is set, for x=44 and k=3, and…
- Assume 32-bit int. What does this snippet do, and what is printed for x=10? c int x = 10; int y = x & (x - 1); printf("%d", y);
- Assume 32-bit int. What is printed? c #define TOGGLE(flags, bit) ((flags) ^= (1 << (bit))) int flags = 0b0110; TOGGLE(flags, 1)…
- Assume 32-bit int. What is printed? c int count = 0; unsigned int x = 0xF0F0F0F0; while (x) { count += x & 1; x >>= 1; } printf("%d"…
- Assume 32-bit int. What is printed? c int x = 5; int y = x & -x; printf("%d", y);
- Assume 32-bit int. What is printed? c unsigned char a = 200; unsigned char b = 100; unsigned char c = a + b; printf("%u", c);