Home Subjects C Programming Preprocessor

C Programming
Preprocessor

C language from basics to advanced placement prep

22 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–22 of 22
Topics in C Programming
Q.21 Hard Preprocessor
What is the problem with this macro?
#define DOUBLE(x) x*x
int result = DOUBLE(2+3);
A No problem, result is 25
B Result is 11 due to operator precedence
C Compilation error
D Result is undefined
Correct Answer:  B. Result is 11 due to operator precedence
EXPLANATION

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

Test
Q.22 Hard Preprocessor
Which statement about #define is TRUE?
A Macros are type-safe like functions
B Macros do not allocate memory at runtime
C Macros cannot take arguments
D Macros are evaluated at runtime
Correct Answer:  B. Macros do not allocate memory at runtime
EXPLANATION

Macros are purely textual substitutions performed by the preprocessor at compile time, not at runtime. They don't allocate memory themselves.

Test
IGET
IGET AI
Online · Exam prep assistant
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