ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#define EMPTY
#define SEMI ;
int x = 5 EMPTY SEMI
printf("%d", x);
  1. A. 5 (EMPTY expands to nothing and SEMI supplies the terminating semicolon)
  2. B. Compilation error: missing semicolon
  3. C. 0
  4. D. Compilation error: EMPTY cannot be used mid-statement

Correct answer: A. 5 (EMPTY expands to nothing and SEMI supplies the terminating semicolon)

EMPTY expands to nothing, so 'int x = 5 EMPTY SEMI' becomes 'int x = 5 ;' once SEMI expands to its literal semicolon — a valid, if unusual, declaration. x is 5.

More C Programming questions

Exams that ask this topic