+ 1
what is the output of this and explain how it works??
#include <stdio.h> #define cube(x)(x*x*x) int main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); return 0; }
8 Answers
+ 1
no that is wrong answer @HBhZ_C anyway thanks for answering
+ 1
The preprocessor substitute every occurrence of cube(x) with x*x*x
So the program actually runs:
a = b++ * b++ * b++;
Wich means 3 * 4 * 5 = 60
While b ends up being 6
+ 1
mohana hemanth as Martin said that's a bad piece of code with unpredictable behaviour.
So it's perfectly fine that one of the possible output is 27.
But the answer is not 27 nor 60, It's what Martin said
0
This code will call the cube function with 3 as param which returns 3*3*3 =>27 .Then a will be 28 and b will be 3.printf function will be called and will disply a and b value .output 28 3
This is my simple thinking and not tested Are i right?
0
What about a value Davide
0
mohana hemanth a is obviously 60
0
Davide answer for a is 27



