Which of the following correctly demonstrates the use of conditional compilation?
A#ifdef DEBUG
printf("Debug mode");
#endif
B#if DEBUG
printf("Debug mode");
#endif
C#ifelse DEBUG
printf("Debug mode");
#endif
D#iftrue DEBUG
Correct Answer:
A. #ifdef DEBUG
printf("Debug mode");
#endif
EXPLANATION
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.
Which header file must be included to use the NULL macro?
A
B
C
DAny of the above
Correct Answer:
D. Any of the above
EXPLANATION
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.
Consider the following code:
#define PI 3.14
#undef PI
#define PI 3.14159
What is the value of PI after execution?
A3.14
B3.14159
CCompilation error
DUndefined
Correct Answer:
B. 3.14159
EXPLANATION
#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.
Which of the following is a difference between #include and #include "file.h"?
ABoth search in the same directories
B searches system directories first, "file.h" searches current directory first
C"file.h" is for local files, is for system files
DBoth B and C
Correct Answer:
D. Both B and C
EXPLANATION
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.
APreprocessor directives are executed during runtime
BPreprocessor directives start with # and are processed before compilation
CPreprocessor can access variables during compilation
DPreprocessor directives are part of the compiled binary
Correct Answer:
B. Preprocessor directives start with # and are processed before compilation
EXPLANATION
Preprocessor directives (starting with #) are processed before the actual compilation by a separate preprocessor tool. They perform text substitution and conditional compilation.