ProgrammingHardCompetitive coding (CP)
What is printed? Assume unsigned int is 32 bits.
What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
unsigned x = 32, b1 = (x >> 1) & 1u, b5 = (x >> 5) & 1u;
if (b1 != b5) x ^= (1u << 1) | (1u << 5);
printf("%u", x);
}- A. 32
- B. 2
- C. 34
- D. 66
Correct answer: B. 2
Bit 5 of 32 is set and bit 1 is clear, so the code flips both bits, giving 32 XOR (2 | 32) = 2. The single set bit moves from position 5 to position 1.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned a = 0xC, b = 0xA, c = 0x9; unsigned m = (a & b) | (b & c) | (a & c)…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 4, 6}, b[] = {2, 3, 8, 9}; int m[7], i = 0, j = 0, k = 0; while (i <…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 9, 2, 9, 1}, n = 5; int mx = a; for (int p = a + 1; p < a + n; p++)…
- What is printed? c #include <stdio.h> int main(void) { int m[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) m[i][j] = i 3…
- How many pairs (i, j) with i < j have an even sum? Compute with this program. c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint16t s = 0; for (int i = 1; i <= 1000; i++) s += i…