Which of the following is NOT a preprocessor directive in C?
Answer: D
#declare is not a valid preprocessor directive. Valid directives include #define, #include, #pragma, #ifdef, #endif, #if, #else, etc.
Q.2Easy
What is the output of the following code?
#define MAX 5
int arr[MAX];
Answer: B
The preprocessor replaces MAX with 5, creating an array of size 5. This is a valid use of macro expansion.
Q.3Easy
Which preprocessor directive is used to include standard library files?
Answer: C
#include <filename> is used for standard library files (searched in standard paths). #include "filename" is used for user-defined header files (searched in current directory first).
Q.4Easy
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.5Easy
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.
Advertisement
Q.6Easy
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.7Easy
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.8Easy
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.9Easy
Which preprocessor directive is used to conditionally compile code based on whether a macro is defined?
Answer: D
#ifdef checks if a macro is defined, #ifndef checks if it's not defined. Both are used for conditional compilation based on macro definition status.
Q.10Easy
Which statement about preprocessor is TRUE?
Answer: B
Preprocessor directives (starting with #) are processed before the actual compilation by a separate preprocessor tool. They perform text substitution and conditional compilation.
Q.11Easy
Which preprocessor directive should be used to check if a macro is NOT defined?
Answer: D
Both #ifndef and #if !defined(MACRO) are equivalent and check if a macro is not defined. #ifndef is simpler syntax for this specific case.
Q.12Easy
Which header file is included using angle brackets in standard C library?
Answer: B
Standard library headers like stdio.h, stdlib.h, string.h are included using angle brackets #include <filename>.
Q.13Easy
Which preprocessor directive is used to define a constant that cannot be changed during program execution?
Answer: A
#define is used to create macro definitions and constants at compile time. #const, #constant, and #fixed are not valid preprocessor directives in C.
Q.14Easy
Which of the following is a difference between #include <file.h> and #include "file.h"?
Answer: D
The angle bracket version searches in standard system directories first, while quoted version searches in the current/local directory first. Both statements B and C correctly describe this distinction.
Q.15Easy
Consider the following code:
#define PI 3.14
#undef PI
#define PI 3.14159
What is the value of PI after execution?
Answer: B
#undef removes the previous definition of PI. The subsequent #define redefines PI as 3.14159. This is valid C syntax and the final value of PI is 3.14159.
Q.16Easy
Which header file must be included to use the NULL macro?
Answer: D
NULL is defined in multiple standard headers including <stdio.h>, <stdlib.h>, <stddef.h>, <string.h>, and others. Any of these can be included to use NULL.
Q.17Easy
Which of the following correctly demonstrates the use of conditional compilation?
Answer: A
Option A uses #ifdef to check if DEBUG is defined, which is correct for conditional compilation. Option B would check if DEBUG has a non-zero value (expression-based). Options C and D have invalid syntax.
Q.18Easy
What is the output of the following code?
#define PI 3.14
int main() { printf("%f", PI); return 0; }
Answer: C
PI is replaced by 3.14 during preprocessing. When printed with %f format specifier, it displays as 3.140000 (default 6 decimal places).
Q.19Easy
What does the ## operator in preprocessor do?
Answer: B
The ## operator concatenates two tokens into one. For example, #define CONCAT(a,b) a##b creates CONCAT(hello, world) → helloworld.
Q.20Easy
Which predefined macro gives the line number in the source file?
Answer: B
__LINE__ expands to the current line number. __FILE__ gives filename, __DATE__ gives compilation date, __STDC__ indicates C standard compliance.