ProgrammingVery hard
printf("%d", __builtin_popcount(1023)); Is this a portable C expression? What does it mean for the count of 1 bits in 1023?
- A. It is standard C and gives 10
- B. It is compiler-specific, although it would give 10 for 1023 on GCC and Clang
- C. It is standard C and gives 9
- D. It is a syntax error in every C compiler
Correct answer: B. It is compiler-specific, although it would give 10 for 1023 on GCC and Clang
__builtin_popcount is a GCC and Clang extension, not standard C. The count of 1 bits in 1023 is 10 in any correct implementation.
More C Programming questions
- The lowest bit that is zero in x = 0b1011 is isolated by ~x & (x + 1). What value does this give?
- With 16-bit unsigned arithmetic, (65535 x 2) & 0xFFFF is what?
- How many multiples of 4 lie between 1 and 100 inclusive?
- What is gcd(84, 36) by the Euclidean algorithm?
- How many divisors does 10 have among 1 through 10?
- int c = 0; for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) if (i == j) c++; printf("%d", c); What is printed?