Test your understanding of the C preprocessor with these 11 multiple-choice questions — #define macros, macro expansion pitfalls, conditional compilation, and include guards. Every question has the answer and a short explanation hidden below it, and the trickier ones link to a full walkthrough with compilable code.
These questions come from our free Android app, C Programming Quiz — 150+ questions across 9 categories with score tracking, if you prefer to practise on your phone.
How to use this page: answer each question yourself before tapping Show answer. If you get one wrong, follow the linked explanation — knowing why the wrong options are wrong is what interviews test.
Question 1 of 11 (Easy)
Which part of the toolchain handles directives like #define and #include?
- The compiler
- The preprocessor
- The linker
- The loader
Show answer
Answer: B — The preprocessor
Lines beginning with # are processed by the C preprocessor before compilation proper begins.
Question 2 of 11 (Hard)
What is the output of this code?
#define SQ(x) x*x
printf("%d", SQ(2 + 3));
- 25
- 11
- 10
- Compile error
Show answer
Answer: B — 11
Macros do textual substitution: SQ(2 + 3) becomes 2 + 3 * 2 + 3 = 2 + 6 + 3 = 11. Always parenthesize macro parameters: #define SQ(x) ((x)*(x)).
Full walkthrough with compilable code: read the detailed explanation.
Question 3 of 11 (Medium)
What is the main purpose of an include guard (#ifndef / #define / #endif)?
- To speed up compilation
- To prevent a header being included more than once
- To hide private functions
- To check for syntax errors
Show answer
Answer: B — To prevent a header being included more than once
Include guards prevent the same header's contents from being included multiple times in one translation unit, which would cause redefinition errors.
Question 4 of 11 (Easy)
Which directive inserts the contents of another file?
- #import
- #include
- #insert
- #use
Show answer
Answer: B — #include
#include tells the preprocessor to textually insert the contents of the named header or source file.
Question 5 of 11 (Medium)
Which preprocessor directive compiles code only if a condition is true?
- #ifdef
- #if
- #when
- #check
Show answer
Answer: B — #if
#if evaluates a constant expression at preprocessing time and includes the code block only if it is non-zero (true).
Question 6 of 11 (Easy)
What is the output of this code?
#define MAX 100
printf("%d", MAX);
- MAX
- 100
- Compile error
- 0
Show answer
Answer: B — 100
The preprocessor replaces MAX with 100 before compilation. printf("%d", 100) prints 100.
Full walkthrough with compilable code: read the detailed explanation.
Question 7 of 11 (Hard)
What does the stringizing operator '#' do in a macro?
- Concatenates two tokens
- Converts a macro argument to a string literal
- Comments out the rest of the line
- Defines a nested macro
Show answer
Answer: B — Converts a macro argument to a string literal
The # operator stringizes its argument: #define STR(x) #x → STR(hello) becomes "hello". It converts the token to a quoted string.
Question 8 of 11 (Medium)
What does '#pragma once' do?
- Runs a function exactly once
- Prevents a header file from being included more than once (non-standard but widely supported)
- Disables compiler warnings
- Enables strict mode
Show answer
Answer: B — Prevents a header file from being included more than once (non-standard but widely supported)
#pragma once is a non-standard but widely supported alternative to traditional include guards. It tells the compiler to include the file only once per translation unit.
Question 9 of 11 (Hard)
What does the token-pasting operator '##' do in a macro?
- Creates a string from two tokens
- Concatenates two tokens into a single token
- Repeats a macro twice
- Defines a nested macro
Show answer
Answer: B — Concatenates two tokens into a single token
## pastes two tokens together. #define CONCAT(a,b) a##b → CONCAT(foo, bar) becomes foobar — a single identifier.
Question 10 of 11 (Medium)
What predefined macro expands to the current source line number?
- __FILE__
- __LINE__
- __DATE__
- __FUNC__
Show answer
Answer: B — __LINE__
__LINE__ is a predefined macro that expands to the current source line number as a decimal integer. __FILE__ gives the filename, __DATE__ the compilation date.
Question 11 of 11 (Easy)
How do you undefine a previously defined macro?
- #remove
- #undef
- #delete
- #clear
Show answer
Answer: B — #undef
#undef removes a previously defined macro, so it is no longer recognized by the preprocessor.
How Did You Score?
All 11 correct means this topic is interview-ready — try the harder timed rounds in the C Programming Quiz app. Missed a few? The guides below cover everything these questions test.
Keep Practising
- #define Macros in C
- Macro Parentheses in C — Why They Matter
- C Aptitude Questions and Answers
- All quiz question walkthroughs
More C Quizzes
- C Basics Quiz — 28 Questions with Answers
- C Operators Quiz — 20 Questions with Answers
- C Memory Management Quiz — 19 Questions with Answers
- C Pointers Quiz — 18 Questions with Answers
- C Arrays and Strings Quiz — 18 Questions with Answers
- C Functions Quiz — 15 Questions with Answers
- C Structs and Unions Quiz — 13 Questions with Answers
- C File I/O Quiz — 13 Questions with Answers