ProgrammingVery hardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 11, y = x & (x + 1);
printf("%u", y);
}- A. 11
- B. 12
- C. 8
- D. 0
Correct answer: C. 8
x & (x + 1) clears the trailing run of 1 bits: 11 = 1011 and 12 = 1100, so the AND is 1000 = 8. 12 is just x + 1, and 0 assumes x and x + 1 can share no bits.
More C Programming questions
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int (p)[3] = 0; printf("%zu", sizeof p); }
- What is printed? Assume the array has space for 5 characters. c #include <stdio.h> int main(void) { char s[5] = "abcd"; printf("%zu"…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 'A' == 65); }
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0; x--; printf("%u", x >> 31); }
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}; printf("%d", (a + 1) + (1 + a)); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (1 << 4) | 3 & 5); }