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 = 1, r = 0;
for (int i = 0; i < 32; i++) {
r = (r << 1) | (x & 1u);
x >>= 1;
}
printf("%u", r);
}- A. 1
- B. 2147483648
- C. 4294967295
- D. 65536
Correct answer: B. 2147483648
Reversing a 32-bit word that holds 1 moves its bit to the top position, 2^31 = 2147483648.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 1000; int p = -1; while (n) { n >>= 1; p++; } printf("%d", p); }
- Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed? c #include…
- What is printed? c #include <stdio.h> int main(void) { const char s = "112233"; int count[10] = {0}; for (const char p = s; p; p++)…
- What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program. c #include…
- How many elements of {0, 2, 1, 3, 4, 7, 6} equal their own index? Count with this program. c #include <stdio.h> int main(void) { int a[] =…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {2, 7, 1}; int e = a + sizeof a / sizeof a[0] - 1; printf("%d", e); }