Preprocessors in C Programming MCQ Questions and Answers
1. Which of the following symbols is used to indicate a preprocessor directive in C?
A) @
B) #
C) $
D) %
Answer: B
2. The #define directive in C is used for:
A) Declaring a function
B) Defining a macro or symbolic constant
C) Including header files
D) Declaring global variables
Answer: B
3. Which of the following is a valid example of a macro definition?
A) #define MAX = 10
B) #define MAX 10
C) define MAX 10;
D) #macro MAX 10
Answer: B
4. The #include <stdio.h> directive is processed by:
A) The compiler
B) The linker
C) The preprocessor
D) The loader
Answer: C
5. Which of the following correctly defines a function-like macro?
A) #define ADD(x, y) x + y
B) #macro ADD(x, y) x + y
C) define ADD(x, y) x + y;
D) #define ADD x, y = x + y
Answer: A
6. Which directive is used to avoid multiple inclusions of the same header file?
A) #ifndef, #define, #endif
B) #ifdef, #endif
C) #pragma once
D) Both A and C
Answer: D
7. What happens if a macro name and a variable name are the same?
A) Macro takes precedence
B) Variable takes precedence
C) Compiler gives an error
D) Linker resolves the conflict
Answer: A
8. Which directive is used to undefine a macro?
A) #remove
B) #undef
C) #clear
D) #reset
Answer: B
9. Which preprocessor operator is used for stringizing in C?
A) ##
B) #
C) $
D) &
Answer: B
10. In a macro definition, the operator ## is used for:
A) Concatenation of tokens
B) String conversion
C) Conditional inclusion
D) Line continuation
Answer: A
11. Which of the following is not a valid preprocessor directive?
A) #define
B) #elif
C) #ifelse
D) #error
Answer: C
12. What is the output of the directive #error “Invalid configuration”?
A) Displays a compile-time warning
B) Displays a compile-time error message
C) Prints a runtime error
D) Ignored by the compiler
Answer: B
13. Which directive can be used to check if a macro has been defined earlier?
A) #ifdef
B) #if
C) #define
D) #endif
Answer: A
14. The directive #pragma is mainly used for:
A) Compiler-specific instructions
B) Memory management
C) Function definition
D) Variable declaration
Answer: A
15. Which of the following correctly continues a macro definition to the next line?
A) By using a comma ,
B) By using a semicolon ;
C) By using a backslash \
D) By using a colon :
Answer: C
16. What is the output of this code?
#define SQR(x) x*x
int a = 3;
int b = SQR(a+1);
A) 16
B) 7
C) 10
D) 8
Answer: B
(Explanation: SQR(a+1) expands to a+1a+1 → 3+13+1 = 7)
17. The macro #define PI 3.14 will be replaced by:
A) A variable declaration
B) A text substitution before compilation
C) A function call
D) A compiler directive after linking
Answer: B
18. Which of the following is a conditional compilation directive?
A) #elif
B) #define
C) #pragma
D) #include
Answer: A
19. If the same header file is included multiple times, what prevents redefinition errors?
A) Function overloading
B) Header guards
C) Macro concatenation
D) Dynamic linking
Answer: B
20. Which of the following lines will correctly include a user-defined header file “myfile.h”?
A) #include <myfile.h>
B) #include myfile.h
C) #include “myfile.h”
D) include “myfile.h”
Answer: C
21. Which preprocessor directive helps in writing platform-dependent code?
A) #pragma
B) #ifdef
C) #error
D) #define
Answer: B
22. Which of the following correctly represents nested conditional compilation?
A) #if, #define, #endif
B) #if, #ifdef, #endif
C) #define, #include, #undef
D) #pragma, #endif, #error
Answer: B
23. If a macro is defined as #define VALUE 5+3, what is the result of 2*VALUE after preprocessing?
A) 16
B) 13
C) 11
D) 10
Answer: B
(Explanation: 25+3 = 13)*
24. Which of the following correctly disables a section of code without using comments?
A) #remove … #endremove
B) #if 0 … #endif
C) #disable … #enddisable
D) #omit … #endomit
Answer: B
25. Which directive is responsible for conditional error generation in compilation?
A) #define
B) #ifdef
C) #error
D) #pragma
Answer: C
26. Which preprocessor directive can help include a header file only if it exists?
A) #ifdef
B) #elif
C) #if __has_include(…)
D) #pragma include
Answer: C
27. What is the correct output of this macro?
#define INC(x) ++x
int a = 5;
printf(“%d”, INC(a));
A) 5
B) 6
C) ++a
D) Compilation error
Answer: B
28. The preprocessor executes:
A) After compilation
B) Before compilation
C) During linking
D) During runtime
Answer: B
29. Which of the following is a compiler-specific directive?
A) #pragma
B) #define
C) #include
D) #if
Answer: A
30. What is the purpose of #line directive in C?
A) It defines line numbering for error messages
B) It specifies the number of lines in a file
C) It includes a source file
D) It defines macros dynamically
Answer: A
31. What does the directive #undef PI do after #define PI 3.14?
A) Reassigns PI to 0
B) Deletes the macro definition of PI
C) Reinitializes PI
D) Raises a compilation error
Answer: B
32. What is the output of this macro evaluation?
#define MULT(a,b) a*b
int x = 2, y = 3;
printf(“%d”, MULT(x+1, y+2));
A) 8
B) 11
C) 10
D) 9
Answer: B
(Explanation: x+1y+2 → 2+13+2 = 7 → 11)
33. What is the correct way to create a macro that returns the greater of two numbers?
A) #define MAX(a,b) (a > b ? a : b)
B) #define MAX(a,b) if(a>b) a else b
C) #macro MAX(a,b) a > b ? a : b
D) define MAX(a,b) a>b?a:b
Answer: A
34. Which of the following preprocessor directives allows selective compilation of code based on conditions?
A) #pragma
B) #ifdef, #endif
C) #define
D) #error
Answer: B
35. The symbol __LINE__ in C preprocessor represents:
A) The current function name
B) The current line number in the source file
C) The current column number
D) The name of the compiler
Answer: B
36. Which of the following predefined macros is used to get the current file name?
A) __DATE__
B) __TIME__
C) __FILE__
D) __LINE__
Answer: C
37. If you write #define AREA(r) 3.14*r*r, what will be the output of AREA(1+1)?
A) 12.56
B) 6.28
C) 9.86
D) 7.85
Answer: B
(Explanation: expands to 3.141+11+1 = 6.28)
38. Which of the following allows defining a macro only if it was not already defined?
A) #ifdef
B) #ifndef
C) #elif
D) #endif
Answer: B
39. The directive #pragma once is mainly used to:
A) Ensure a header file is included only once
B) Stop compiler optimizations
C) Generate warnings
D) Link dynamic libraries
Answer: A
40. What happens if #include cannot find the specified header file?
A) The preprocessor skips it silently
B) The compiler throws a fatal error
C) The linker ignores it
D) The program still compiles successfully
Answer: B
41. Which of the following is used for debugging information during compilation?
A) #error
B) #warning
C) #pragma message
D) #line
Answer: C
42. Which of the following cannot appear inside a macro definition?
A) Function call
B) Another #define directive
C) Arithmetic expression
D) Conditional operator
Answer: B
43. Which directive helps to include different header files for different operating systems?
A) #if defined(…)
B) #pragma include
C) #define include
D) #error include
Answer: A
44. What will the preprocessor output after expanding this line?
#define SUM 2+3
int x = SUM * 2;
A) int x = 10;
B) int x = 2+3*2;
C) int x = 5*2;
D) Compilation error
Answer: B
45. Which macro gives the date when the source file was compiled?
A) __DATE__
B) __TIME__
C) __FILE__
D) __LINE__
Answer: A
46. Which directive can produce a custom compilation message?
A) #pragma message(“Compiling…”)
B) #print(“Compiling…”)
C) #debug(“Compiling…”)
D) #warn(“Compiling…”)
Answer: A
47. What is the main purpose of macros in C?
A) Improve runtime efficiency
B) Perform text substitution before compilation
C) Manage memory automatically
D) Handle runtime errors
Answer: B
48. What is the effect of defining a macro without a value, like #define FLAG?
A) It defines a macro with a default integer value
B) It defines a symbolic flag for conditional compilation
C) It causes an error
D) It reserves a memory space
Answer: B
49. What is the correct syntax for a multi-line macro definition?
A) #define MACRO { code; code; }
B) #define MACRO(x) statement1; statement2;
C)
#define MACRO(x) statement1; \
statement2;
D) #macro(x) statement1; statement2;
Answer: C
50. Which directive provides file name mapping for debugging?
A) #line
B) #pragma
C) #debug
D) #alias
Answer: A
51. Which of these is not processed by the preprocessor?
A) Removing comments
B) Expanding macros
C) Conditional compilation
D) Optimizing code
Answer: D
52. Which directive is used to suppress multiple inclusions of the same file?
A) #ifndef
B) #define
C) #endif
D) All of the above
Answer: D
53. What is the output of this macro evaluation?
#define ADD(a,b) (a + b)
printf(“%d”, ADD(2,3)*2);
A) 10
B) 7
C) 12
D) 8
Answer: A
54. What is the significance of using parentheses in macros like (a + b)?
A) They improve readability only
B) They prevent precedence-related errors during expansion
C) They are optional in all macros
D) They have no effect in preprocessing
Answer: B
55. What happens when a macro name appears in its own definition?
A) Causes an infinite loop
B) Causes recursive macro expansion
C) Causes a compilation error
D) Macro name is treated as plain text
Answer: D
56. The preprocessor directive #include is used for:
A) Linking object files
B) Inserting file contents before compilation
C) Compiling header files separately
D) Including only system libraries
Answer: B
57. Which of the following correctly combines two tokens in a macro?
A) #token1 token2
B) token1##token2
C) token1#token2
D) ##token1token2
Answer: B
58. Which of the following can be defined using macros?
A) Functions
B) Constants
C) Expressions
D) All of the above
Answer: D
59. If you write #define VALUE (2*3) and later #undef VALUE, what happens to further references of VALUE?
A) They are replaced by (2*3)
B) They are ignored
C) They cause an error
D) VALUE is treated as an undefined identifier
Answer: D
60. What is the purpose of #if defined(MACRO)?
A) To define a macro
B) To test if a macro has been defined
C) To redefine a macro
D) To remove a macro
Answer: B
61. Which directive can produce a user-defined compile-time error message?
A) #error
B) #warning
C) #pragma
D) #debug
Answer: A
62. Which preprocessor directive ensures compilation only for a specific compiler version?
A) #if COMPILER_VERSION
B) #pragma
C) #if __VERSION__
D) #ifdef COMPILER_VERSION
Answer: C
63. Which of the following directives cannot be nested?
A) #ifdef
B) #elif
C) #pragma
D) #if
Answer: C
64. What is the effect of using #pragma once and header guards together?
A) Causes duplication
B) No conflict — both ensure single inclusion
C) Reduces compilation speed
D) Causes syntax error
Answer: B
65. What is the output of this macro definition?
#define DOUBLE(x) (x + x)
printf(“%d”, DOUBLE(2+3));
A) 10
B) 7
C) 9
D) 8
Answer: A
66. Which preprocessor directive can include files from a relative path?
A) #include “../header.h”
B) #file “../header.h”
C) #pragma include “../header.h”
D) #path “../header.h”
Answer: A
67. Which of the following is not a valid macro naming rule?
A) Macro names are case sensitive
B) Macro names can include spaces
C) Macro names can contain underscores
D) Macro names cannot start with digits
Answer: B
68. Which directive allows assigning an alias name to a file for line tracking?
A) #pragma file
B) #line
C) #error
D) #debug
Answer: B
69. The preprocessing stage occurs:
A) After linking
B) Before compilation
C) After code optimization
D) During execution
Answer: B
70. Which directive stops compilation immediately when encountered?
A) #stop
B) #error
C) #abort
D) #break
Answer: B
71. The __TIME__ macro expands to:
A) The current system time
B) The time of code execution
C) The time when the code was compiled
D) The CPU clock cycles
Answer: C
72. Which of the following is true about macros?
A) Macros consume memory during runtime
B) Macros are expanded inline before compilation
C) Macros are stored in the symbol table
D) Macros are executed like functions
Answer: B
73. What happens if you write #define MAX 10 20?
A) Syntax error
B) Macro defined as “10 20” (entire text)
C) Only 10 is assigned
D) Only 20 is assigned
Answer: B
74. Which of these directives can help in version management of source code?
A) #if, #elif, #endif
B) #pragma
C) #define version
D) #error
Answer: A
75. Which preprocessor directive can be used to control optimization behavior?
A) #pragma optimize
B) #define optimize
C) #ifdef optimize
D) #error optimize
Answer: A
76. What will this code print?
#define VALUE 10
#undef VALUE
printf(“%d”, VALUE);
A) 10
B) 0
C) Compilation error
D) Undefined behavior
Answer: C
77. Which directive can enable or disable certain compiler warnings?
A) #pragma warning
B) #error
C) #warning
D) #define warn
Answer: A
78. Which symbol indicates line continuation in macros?
A) /
B) \
C) :
D) ;
Answer: B
79. Which of these directives cannot appear inside a function?
A) #define
B) #include
C) #pragma
D) All of the above
Answer: D
80. Which of the following is the correct expansion of this macro?
#define PRINT(x) printf(“Value = %d”, x)
PRINT(5+3);
A) printf(“Value = %d”, 5+3);
B) printf(“Value = %d”, 8);
C) printf(Value = 8);
D) Compilation error
Answer: A
81. What happens when a macro parameter name matches another macro name?
A) Inner macro expands first
B) Outer macro expands first
C) Macro expansion is undefined
D) The parameter is treated as a literal
Answer: D
82. The directive #pragma once is supported by:
A) C89 and later
B) Compiler implementation
C) ANSI C standard
D) Only in GCC
Answer: B
83. What is the output of printf(“%s”, __FILE__);?
A) The name of the current source file
B) The directory name
C) The binary file name
D) The executable name
Answer: A
84. Which of the following preprocessor symbols expands to the current compilation date and time?
A) __DATE__ __TIME__
B) __FILE__ __LINE__
C) __DATE_TIME__
D) __NOW__
Answer: A
85. Which directive can be used to force inclusion of a header file?
A) #force
B) #include_next
C) #pragma include
D) #insert
Answer: B
86. The preprocessor removes comments:
A) Before tokenization
B) After preprocessing
C) During macro expansion
D) During linking
Answer: A
87. Which directive is used to issue compiler instructions specific to implementation?
A) #pragma
B) #define
C) #error
D) #if
Answer: A
88. What is the result of using macros to define constants instead of const variables?
A) They increase type safety
B) They are replaced before type checking
C) They use more memory
D) They require initialization
Answer: B
89. Which directive marks the end of a conditional compilation block?
A) #elif
B) #else
C) #endif
D) #end
Answer: C
90. Which of these is not a predefined macro?
A) __STDC__
B) __LINE__
C) __AUTHOR__
D) __FILE__
Answer: C
91. What is the result of #define CUBE(x) (x*x*x) and CUBE(2+1)?
A) 9
B) 27
C) 15
D) 21
Answer: D
(Explanation: Expands to (2+12+12+1) = 7 → 21)
92. Which of these can cause logical errors in macros?
A) Missing parentheses
B) Excessive parameters
C) Using const values
D) Using float values
Answer: A
93. What happens when #ifdef condition fails?
A) The block under it is skipped
B) The block executes normally
C) Compilation stops
D) A warning is raised
Answer: A
94. What does the preprocessor directive #elif stand for?
A) Else if
B) Else include file
C) Else inline function
D) Else identifier
Answer: A
95. Which directive is used to generate warnings during compilation without stopping it?
A) #warn
B) #warning
C) #error
D) #pragma alert
Answer: B
96. Which preprocessor feature is useful in writing portable programs?
A) Conditional compilation
B) Header file inclusion
C) Macro expansion
D) All of the above
Answer: D
97. What is the output of:
#define VALUE 10
#define VALUE 20
printf(“%d”, VALUE);
A) 10
B) 20
C) Compilation error
D) Undefined
Answer: B
98. What is the meaning of this directive?
#if 0
printf(“Hidden”);
#endif
A) Prints “Hidden”
B) Compiles conditionally
C) Comment-like exclusion
D) Causes error
Answer: C
99. Which of these macros is automatically defined by the compiler?
A) __cplusplus
B) __AUTHOR__
C) __TIMEZONE__
D) __DEBUG__
Answer: A
100. Which directive allows defining symbolic constants dynamically based on expressions?
A) #define
B) #if
C) #pragma
D) #calc
Answer: A
