C Preprocessor & Macros Quiz

The C preprocessor rewrites your code before the compiler sees it, which makes macros powerful and easy to get wrong. This quiz covers missing parentheses, arguments evaluated twice, # and ##, conditional compilation and the idioms that keep macros safe.

Medium 10 questions ~6 minutes Pass at 80% C17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

#include <stdio.h>

#define SQUARE(x) x * x

int main(void) {
    printf("%d\n", SQUARE(2 + 3));
    return 0;
}
Show the answer

D. 11 Macros substitute text, so this becomes 2 + 3 * 2 + 3, which is 2 + 6 + 3 = 11. Write #define SQUARE(x) ((x) * (x)).

What this quiz covers

  • Why macro bodies and parameters need parentheses
  • Arguments that are evaluated more than once
  • Stringizing with # and token pasting with ##
  • #ifdef, #undef and predefined macros
  • Include guards and the do { ... } while (0) idiom

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.