C program output
#define max 10+2
This is a preprocessor. it is not reasonable.
This is stupid.
it just replaces the text.
max*max
decide
10+2*10+2
which the
10+(2*10)+2
due to operator precedence which
10 + 20 + 2
i.e. 32
Also, you should always avoid preprocessor macros and use . You may or may not want to also consider using a variable static const
insteadconst
or enum
instead of #define
; each has its own tradeoffs, refer to a similar question: "static const" vs "# define" vs "enumeration" .
If you want to stick with the preprocessor, you can simply use:
#define max (10+2)
Since the parenthesized code will assume operator certainty.
source to share