ProgrammingHardCompetitive coding (CP) · C internals

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { #define SQ(x) ((x) * (x)) printf("%d", SQ(2 + 3)); return 0; }

  1. A. 13
  2. B. 11
  3. C. 25
  4. D. Compilation error

Correct answer: C. 25

Parenthesising both the parameter and the whole expansion fixes the earlier trap: SQ(2+3) expands to ((2+3)*(2+3)) = 25.

More C Programming questions

Exams that ask this topic