+ 6
What does this mean: #define x 5+2? And how would C++ colpile it?
I fond this: #define x 5+2 int main(){ int i= x*x*x; cout << i; return 0; } // the out put is 27 !!! i don't understand how !!! Can any one explane, please!
4 Answers
+ 16
@ KrOW @Ace, thanks for the good explanation đđ
+ 6
#define run in preprocessor context and when it run before compilation... it essentially replace the content of defined identifier with corrispondent value in your case:
#define x 5+2
int i= x*x*x;
here x will be substituited to 5+2 as:
int i= 5+2*5+2*5+2;
that is 5+10+10+2 = 27
+ 3
@KrOW @Ace ; Thanks a lot for answering me. So, if i understand well; in this example:
#define x 10+10
int i=x/10;
cout<<i;
It will be compiled like
int i=10+10/10;
and the result will be 11
+ 2
đ