ProgrammingHardCompetitive coding (CP)
What is printed? Assume unsigned long long is 64 bits.
What is printed? Assume unsigned long long is 64 bits.
#include <stdio.h>
int main(void) {
unsigned long long x = (1ULL << 40) - 1;
int c = 0;
for (; x; x &= x - 1) c++;
printf("%d", c);
}- A. 39
- B. 41
- C. 30
- D. 40
Correct answer: D. 40
(1 << 40) - 1 has forty consecutive set bits, and each loop step clears the lowest one.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}; int p = a; p += 2; printf("%d", p - (p - 2)); }
- What is printed? Assume unsigned short is 16 bits and int is 32 bits. c #include <stdio.h> int main(void) { printf("%d", (unsigned…
- How many binary strings of length 4 contain no two consecutive 1s? Compute with this recursive program. c #include <stdio.h> int f(int n)…
- What is printed? c #include <stdio.h> int main(void) { unsigned char a = 100, b = 200; unsigned char s = (unsigned char)(a + b) / 2…
- How many times does the loop body run? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0, j = 0; i < 4 && j < 4; i++, j +=…
- What is printed? c #include <stdio.h> void inc(int p, int n) { while (n--) (p++)++; } int main(void) { int a[] = {1, 2, 3}; inc(a, 2)…