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?

  1. A. It is standard C and gives 10
  2. B. It is compiler-specific, although it would give 10 for 1023 on GCC and Clang
  3. C. It is standard C and gives 9
  4. 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

Exams that ask this topic