Programming Languages C Objective
Mar 08, 2013

What will be output the following c
code?
#define x 5+2
void main(){
int i;
i=x*x*x;
printf("%d",i);
}

Choose the correct answer:
A) 129
B) 37
C) 27
D) Compiler error
Detailed Explanation

As we know #define is token pasting preprocessor it only paste the
value of micro constant in the program before the actual compilation
start. If you will see intermediate file you will find:
test.c 1:
test.c 2: void main(){
test.c 3: int i;
test.c 4: i=5+2*5+2*5+2;
test.c 5: printf("%d",i);
test.c 6: }
test.c 7:
You can absorb #define only pastes the 5+2 in place of x in program.
So,
i=5+2*5+2*5+2
=5+10+10+2
=27

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback