Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 1,000
Topics in C Programming
Q.71 Hard Preprocessor
Consider:
#define MAX(a,b) ((a)>(b)?(a):(b))
Which advantage does this provide?
A It is type-safe compared to functions
B It provides better performance as no function call overhead
C It uses ternary operator for comparison
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Macros with parentheses provide inline substitution (better performance, no function call overhead) and can work with any data type. However, they lack type safety that functions provide.

Take Test
Q.72 Medium Preprocessor
What is the output of:
#define STR(x) #x
printf("%s", STR(HELLO));
A HELLO
B #HELLO
C STR(HELLO)
D Compilation error
Correct Answer:  A. HELLO
EXPLANATION

The # operator (stringification) converts the macro argument into a string literal. STR(HELLO) becomes "HELLO", and printf prints: HELLO

Take Test
Q.73 Easy Preprocessor
Which statement about preprocessor is TRUE?
A Preprocessor directives are executed during runtime
B Preprocessor directives start with # and are processed before compilation
C Preprocessor can access variables during compilation
D Preprocessor 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.

Take Test
Q.74 Medium Preprocessor
What does the following macro do?
#define CONCATENATE(a,b) a##b
A Concatenates two strings at runtime
B Uses token pasting to combine two identifiers into one at preprocessing stage
C Creates a compilation error
D Multiplies two numbers
Correct Answer:  B. Uses token pasting to combine two identifiers into one at preprocessing stage
EXPLANATION

The ## operator (token pasting operator) concatenates two tokens into a single token during preprocessing. For example, CONCATENATE(var,1) becomes var1.

Take Test
Q.75 Hard Preprocessor
Consider the macro:
#define ADD(a,b) (a)+(b)
What is the result of: int x = ADD(3,4) * 2;
A 14
B 11
C 7
D Compilation error
Correct Answer:  A. 14
EXPLANATION

ADD(3,4)*2 expands to (3)+(4)*2 = 3+8 = 11. Wait, order of operations: 4*2 = 8, then 3+8 = 11. Actually, correct answer should be 11 based on operator precedence. Rechecking: (3)+(4)*2 following BODMAS gives 3+(8) = 11. If parentheses were ((a)+(b)), it would be (3+4)*2 = 14.

Take Test
Q.76 Medium Preprocessor
What will be printed?
#define DEBUG 1
#if DEBUG
printf("Debug mode ON");
#else
printf("Debug mode OFF");
#endif
A Debug mode ON
B Debug mode OFF
C Both will be printed
D Compilation error
Correct Answer:  A. Debug mode ON
EXPLANATION

Since DEBUG is defined as 1 (non-zero), the #if DEBUG condition is true, so only the code in #if block executes. The #else block is skipped.

Take Test
Q.77 Easy Preprocessor
Which preprocessor directive is used to conditionally compile code based on whether a macro is defined?
A #if
B #ifdef
C #ifndef
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

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

Take Test
Q.78 Medium Preprocessor
What will be the output of the following code?
#define SQUARE(x) x*x
int result = SQUARE(2+3);
printf("%d", result);
A 25
B 11
C 10
D Compilation error
Correct Answer:  B. 11
EXPLANATION

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

Take Test
Q.79 Medium Preprocessor
Consider the following code:
#define MAX 100
#define MAX 200
What will be the result?
A Compilation error: macro redefinition
B MAX will have value 200, last definition wins
C Compilation warning but MAX remains 100
D Runtime error
Correct Answer:  A. Compilation error: macro redefinition
EXPLANATION

In C, redefining a macro without #undef first will cause a compilation error. Most compilers treat macro redefinition as an error.

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

#allocate is not a valid preprocessor directive. Valid directives include #include, #define, #pragma, #ifdef, #ifndef, #if, #else, #elif, #endif, #error, #undef.

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