c++ - I don't understand the working of the following Macro -


what mathematical equivalent equation of following macro

#define sq(a) (a*a ) int answer sq(2 + 3 ); 

output 11 case ,

int answer sq(2 + 4); 

is 14 can't figure out equation outputs.

the macro defined lacks brackets keep arithmetic working want. remember preprocessor macros doing text replacement solely. you'll calling shown expands

int answer (2 + 4 * 2 + 4); 

and according operator precedence result 14.

write macro

#define sq(a) ((a)*(a)) 

to result expected.


Comments

Popular posts from this blog

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -