What is the difference between #include <file.h> and #include "file.h"?
Answer: B
#include <file.h> searches in standard system include directories. #include "file.h" searches in the current working directory first, then system directories. This allows you to override system headers with local versions.
Q.82Medium
Consider nested macro expansion:
#define A B
#define B 5
printf("%d", A);
What is printed?
Answer: B
The preprocessor expands A to B in the first pass. In the second pass, it recognizes B as a macro and expands it to 5. Nested macro expansion is allowed and the final result is 5. The preprocessor performs multiple expansion passes as needed.
Q.83Medium
Which statement about __VA_ARGS__ in variadic macros is CORRECT?
Answer: A
__VA_ARGS__ (C99 feature) represents all variable arguments after the required parameters. It can be empty if no extra arguments are provided. It must be used with '...' in the macro definition. C89/C90 don't support variadic macros.
Q.84Easy
What happens when #if 0...#endif wraps a block of code?
Answer: B
#if 0...#endif is used to disable code during preprocessing. The enclosed code is skipped entirely and doesn't appear in the compiled output. This is more efficient than C-style comments for large blocks and maintains nested comment compatibility.
Q.85Hard
Which of the following will cause infinite recursion when used?
#define RECURSE() RECURSE()
Answer: C
The C preprocessor does not detect or prevent recursive macro expansion in its definition. RECURSE() will expand to RECURSE() infinitely, causing the preprocessor to hang or run out of memory. Modern compilers have safeguards, but theoretically this creates infinite expansion.
Advertisement
Q.86Easy
What is the purpose of defined() operator in preprocessor conditionals?
Answer: A
defined(MACRO) is used in #if and #elif directives to test if a macro is defined. Example: #if defined(DEBUG) ... #endif. It's equivalent to #ifdef but can be used in expressions with logical operators like && and ||.
Q.87Medium
Consider: #define DOUBLE(x) (2*(x))
int main() { int arr[DOUBLE(5)]; ... }
What is the size of the array?
Answer: B
The macro DOUBLE(5) expands to (2*(5)) = 10 at preprocessing time. Array declarations require compile-time constant expressions, and macro-expanded constants qualify. The array has 10 elements. This works because the macro creates a constant expression that the compiler can evaluate.
Q.88Easy
What is the primary purpose of the C preprocessor?
Answer: A
The preprocessor is a text processing tool that processes source code before actual compilation, handling directives like #define, #include, and macros.
Q.89Easy
Which directive is used to conditionally compile code based on a logical condition?
Answer: B
#if evaluates constant expressions for conditional compilation. #ifdef checks if a macro is defined, #define creates macros, and #pragma provides compiler-specific directives.
Q.90Medium
What will be the preprocessed output of the following code?
#define SQUARE(x) x*x
int result = SQUARE(5+3);
Answer: C
Without parentheses, SQUARE(5+3) expands to 5+3*5+3, which evaluates to 5+15+3=23 due to operator precedence, not (5+3)*(5+3)=64. This demonstrates why macro parameters need parentheses.
Q.91Medium
What does the __VA_ARGS__ preprocessor feature allow in variadic macros?
Answer: A
__VA_ARGS__ allows macros to accept a variable number of arguments. Example: #define PRINT(...) printf(__VA_ARGS__) enables flexible argument passing.
Q.92Medium
What is the output of the following code?
#define STR(x) #x
printf(STR(Hello World));
Answer: B
The # operator (stringification) converts the macro argument into a string literal. STR(Hello World) becomes "Hello World", which printf prints with quotes.
Q.93Medium
Consider this preprocessor code:
#define CONCAT(a,b) a##b
int CONCAT(var,1) = 10;
What is the actual variable name created?
Answer: B
The ## operator (token pasting) concatenates tokens directly. CONCAT(var,1) produces var1 as the variable name, not a##b.
Q.94Hard
What will happen if a macro is defined multiple times with different definitions in the same compilation unit?
#define SIZE 10
#define SIZE 20
Answer: A
Redefining a macro with a different value in the same compilation unit causes a compilation error. To redefine, you must #undef first.
Q.95Medium
Consider the following preprocessor directives:
#define MAX 100
#define MIN 50
#undef MAX
#define MAX 200
int main() {
printf("%d", MAX);
return 0;
}
What will be the output of this program?
Answer: A
The #undef directive undefines the previously defined macro MAX (which was 100). Then MAX is redefined as 200. So printf will output 200. The #undef allows redefining macros without compilation errors.