C Preprocessor Quiz — 11 Questions with Answers

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?

  1. The compiler
  2. The preprocessor
  3. The linker
  4. 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));
  1. 25
  2. 11
  3. 10
  4. 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)?

  1. To speed up compilation
  2. To prevent a header being included more than once
  3. To hide private functions
  4. 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?

  1. #import
  2. #include
  3. #insert
  4. #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?

  1. #ifdef
  2. #if
  3. #when
  4. #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);
  1. MAX
  2. 100
  3. Compile error
  4. 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?

  1. Concatenates two tokens
  2. Converts a macro argument to a string literal
  3. Comments out the rest of the line
  4. 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?

  1. Runs a function exactly once
  2. Prevents a header file from being included more than once (non-standard but widely supported)
  3. Disables compiler warnings
  4. 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?

  1. Creates a string from two tokens
  2. Concatenates two tokens into a single token
  3. Repeats a macro twice
  4. 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?

  1. __FILE__
  2. __LINE__
  3. __DATE__
  4. __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?

  1. #remove
  2. #undef
  3. #delete
  4. #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

More C Quizzes