In the macro definition below, what does '#' symbol do? What is this syntax (#x) here?
#define print(x) cout<<(#x)<<" : "<<x<<endl;
#
is the stringify operator. It turns the macro argument x
into a string literal.
I can see no reason for the extra parens, #define print(x) cout << #x <<" : " << x << endl;
would work just as well. Even better would be #define print(x) cout << #x <<" : " << (x) << endl;
because the second use of x
might require parens to be parsed correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With