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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -

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