Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
What is the problem with this macro?
#define DOUBLE(x) x*x
int result = DOUBLE(2+3);
#define DOUBLE(x) x*x
int result = DOUBLE(2+3);
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))
Which statement about #define is TRUE?
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.