C Programming — Preprocessor
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in Preprocessor
Q.91 Medium Preprocessor
What will happen if you define the same macro twice with different values?
A Compilation error
B First definition is ignored, second is used
C Both definitions are active
D Runtime error occurs
Correct Answer:  B. First definition is ignored, second is used
EXPLANATION

When a macro is redefined, the new definition replaces the old one. Some compilers may issue a warning about redefinition.

Take Test
Q.92 Easy Preprocessor
What is the output?
#define MAX(a,b) (a>b?a:b)
printf("%d", MAX(10, 5));
A 10
B 5
C Error
D 15
Correct Answer:  A. 10
EXPLANATION

The macro expands to (10>5?10:5) which evaluates to 10 since the condition is true.

Take Test
Q.93 Medium Preprocessor
What is the difference between #include and #include "myheader.h"?
A No difference, both are equivalent
B First searches in standard paths, second in current directory
C First is for functions, second is for variables
D #include "" is deprecated
Correct Answer:  B. First searches in standard paths, second in current directory
EXPLANATION

Angle brackets search in standard system directories. Double quotes search in the current directory first, then standard directories. This is the standard convention.

Take Test
Q.94 Medium Preprocessor
Which of the following shows the correct order of preprocessor directives in a C program?
A #include, #define, #ifndef, #endif
B #define, #include, #ifdef, #endif
C Any order is valid
D #include must be first
Correct Answer:  C. Any order is valid
EXPLANATION

Preprocessor directives can appear in any order in the source code. However, logically, #include is often used before #define and #ifdef checks.

Take Test
Q.95 Medium Preprocessor
What is the purpose of the #ifdef directive?
A To check if a macro is defined
B To include a file conditionally
C To define a new macro
D To undefine a macro
Correct Answer:  A. To check if a macro is defined
EXPLANATION

#ifdef checks if a macro identifier is currently defined. Code following it is compiled only if the macro is defined.

Take Test
Advertisement
Q.96 Medium Preprocessor
What is the output of this code?
#define ADD(a,b) a+b
int result = ADD(5,3)*2;
A 16
B 11
C Error
D 8
Correct Answer:  A. 16
EXPLANATION

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.

Take Test
Q.97 Easy Preprocessor
What does the following preprocessor directive do?
#define SQUARE(x) ((x)*(x))
A Defines a function named SQUARE
B Defines an object-like macro
C Defines a function-like macro
D Creates a compilation error
Correct Answer:  C. Defines a function-like macro
EXPLANATION

This is a function-like macro that takes parameter x and expands to ((x)*(x)). The parentheses around x prevent operator precedence issues.

Take Test
Q.98 Easy Preprocessor
Which preprocessor directive is used to include standard library files?
A #include
B #include "filename"
C Both A and B
D #import
Correct Answer:  C. Both A and B
EXPLANATION

#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).

Take Test
Q.99 Easy Preprocessor
What is the output of the following code?
#define MAX 5
int arr[MAX];
A Compilation error
B Array of size 5 is created
C Runtime error
D Preprocessor error
Correct Answer:  B. Array of size 5 is created
EXPLANATION

The preprocessor replaces MAX with 5, creating an array of size 5. This is a valid use of macro expansion.

Take Test
Q.100 Easy Preprocessor
Which of the following is NOT a preprocessor directive in C?
A #define
B #include
C #pragma
D #declare
Correct Answer:  D. #declare
EXPLANATION

#declare is not a valid preprocessor directive. Valid directives include #define, #include, #pragma, #ifdef, #endif, #if, #else, etc.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips