[Solved] I don’t understand the working of the following Macro [closed]


The macro you defined lacks brackets to keep the arithmetic working as you want. Remember preprocessor macros are doing text replacement solely. So what you’ll get from calling it as you shown expands to

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

and according operator precedence the result is 14.

Write your macro as

#define SQ(a) ((a)*(a))

to get the result you expected.

1

solved I don’t understand the working of the following Macro [closed]