Question 7
Back to Exercise
The program should print 12 (double of 3, times 2). What does it print, and why?
#include <stdio.h>
#define DOUBLE(x) x + x
int main(void) {
printf("%d\n", DOUBLE(3) * 2);
return 0;
}
- A 12
- B 9 – the expansion is 3 + 3 * 2, and * binds before + Correct
- C 6
- D It does not compile
Correct Answer: Option B
A macro pastes text; precedence then applies to the result. Bracket the whole body and each parameter: #define DOUBLE(x) ((x) + (x)) – or use an inline function.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!