ProgrammingHardAccenture · Capgemini · C

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 SQUARE(x) x * x printf("%d", SQUARE(2 + 3)); return 0; }

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

Correct answer: D. 11

Macro substitution is purely textual: SQUARE(2+3) expands to 2 + 3 * 2 + 3, which with normal precedence is 2 + 6 + 3 = 11, not 25.

More C Programming questions

Exams that ask this topic