C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.
What does the following preprocessor directive do? #define SQUARE(x) ((x)*(x))
Answer: C
This is a function-like macro that takes parameter x and expands to ((x)*(x)). The parentheses around x prevent operator precedence issues.
Q.882Medium
What is the output of this code? #define ADD(a,b) a+b int result = ADD(5,3)*2;
Answer: A
The macro expands to 5+3*2 = 5+6 = 11, not 16. However, due to operator precedence, it becomes 5+3*2. Actually, it expands correctly to (5+3)*2 = 16 when evaluated.
Q.883Medium
What is the purpose of the #ifdef directive?
Answer: A
#ifdef checks if a macro identifier is currently defined. Code following it is compiled only if the macro is defined.
Q.884Medium
Which of the following shows the correct order of preprocessor directives in a C program?
Answer: C
Preprocessor directives can appear in any order in the source code. However, logically, #include is often used before #define and #ifdef checks.
Q.885Medium
What is the difference between #include <stdio.h> and #include "myheader.h"?
Answer: B
Angle brackets search in standard system directories. Double quotes search in the current directory first, then standard directories. This is the standard convention.
Q.886Easy
What is the output? #define MAX(a,b) (a>b?a:b) printf("%d", MAX(10, 5));
Answer: A
The macro expands to (10>5?10:5) which evaluates to 10 since the condition is true.
Q.887Medium
What will happen if you define the same macro twice with different values?
Answer: B
When a macro is redefined, the new definition replaces the old one. Some compilers may issue a warning about redefinition.
Q.888Easy
What is the purpose of the #undef directive?
Answer: A
#undef is used to remove the definition of a macro so it cannot be used in subsequent code.
Q.889Medium
What is the output of this code? #define SWAP(a,b) {int temp=a; a=b; b=temp;} int x=5, y=10; SWAP(x,y); printf("%d %d", x, y);
Answer: B
The SWAP macro exchanges x and y values using a temporary variable. After the swap, x becomes 10 and y becomes 5.
Q.890Medium
What does the ## operator do in a macro?
Answer: A
The ## operator (token pasting) concatenates two tokens into a single token during macro expansion.
Q.891Medium
What is the output? #define STR(x) #x printf("%s", STR(hello));
Answer: A
The # operator (stringification) converts the macro argument into a string literal. STR(hello) becomes "hello" as a string.
Q.892Hard
Which statement about #define is TRUE?
Answer: B
Macros are purely textual substitutions performed by the preprocessor at compile time, not at runtime. They don't allocate memory themselves.
Q.893Hard
What is the problem with this macro? #define DOUBLE(x) x*x int result = DOUBLE(2+3);
Answer: B
The macro expands to 2+3*2+3 = 2+6+3 = 11, not 25. This is because x is not parenthesized. Should use #define DOUBLE(x) ((x)*(x))
Q.894Hard
What will be the output? #define MIN(a,b) ((a)<(b)?(a):(b)) int x=5; int y=10; int z = MIN(x++, y++);
Answer: A
The macro expands to ((x++)<(y++)?(x++):(y++)). In the condition, x++ returns 5 and increments x to 6. Since 5<10 is true, x++ is evaluated again (x becomes 7, but z gets 6). Actually, this shows side effects problem - x becomes 7, y stays 10.
Q.895Hard
What is the difference between #if and #ifdef?
Answer: A
#ifdef checks if a macro is defined (exists). #if evaluates a constant integer expression (can check macro values, compare numbers, etc.).
Q.896Hard
What preprocessor features should be avoided for safer code?
Answer: B
Function-like macros can cause issues due to multiple evaluation of arguments and operator precedence problems. Modern C prefers inline functions and const for safety.
Q.897Easy
What is the primary role of the C preprocessor in the compilation process?
Answer: A
The preprocessor is a separate program that processes source code before the compiler. It handles directives like #include, #define, and #ifdef.
Q.898Easy
Which of the following is NOT a preprocessor directive?
Answer: D
#allocate is not a valid preprocessor directive. Valid directives include #include, #define, #pragma, #ifdef, #ifndef, #if, #else, #elif, #endif, #error, #undef.
Q.899Medium
Consider the following code: #define MAX 100 #define MAX 200 What will be the result?
Answer: A
In C, redefining a macro without #undef first will cause a compilation error. Most compilers treat macro redefinition as an error.
Q.900Medium
What will be the output of the following code? #define SQUARE(x) x*x int result = SQUARE(2+3); printf("%d", result);
Answer: B
SQUARE(2+3) expands to 2+3*2+3 = 2+6+3 = 11 due to operator precedence. Macros don't evaluate arguments; they substitute text directly. Safe macro should be ((x)*(x)).