ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 0xB, p = 0;
for (; x; x &= x - 1) p ^= 1;
printf("%u", p);
}- A. 0
- B. 3
- C. 1
- D. 2
Correct answer: C. 1
0xB = 1011 has three set bits, and XORing 1 for each one leaves the parity 1.
More C Programming questions
- What is printed? c #include <stdio.h> int sum(int m[][3], int r) { int s = 0; for (int i = 0; i < r; i++) for (int j = 0; j < 3; j++) s +=…
- What is printed? Assume long is 8 bytes and int is 4 bytes. c #include <stdio.h> int main(void) { printf("%zu %zu", sizeof(1L)…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 10 / 3 3 + 10 % 3); }
- What is printed? c #include <stdio.h> int main(void) { unsigned char c = 1; printf("%d", -c); }
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "hello"; char p = strchr(s, 'l'); printf("%ld"…
- How many moves does this recursive Towers of Hanoi program make for 4 disks? Compute with the program. c #include <stdio.h> int moves = 0…