Macro (#define ...
) are only text replacement.
With this version:
#define ALPHA 2-1
#define BETA ALPHA*2
The preprocessor replace BETA
by ALPHA*2
then replace ALPHA
by 2-1
. When the macro expansion is over, BETA
is replaced by 2-1*2
which is (due to operator precedence) equal to 2-(1*2)=0
When you add the parenthesis around the "value of ALPHA
" (ALPHA
doesn’t really have a value since macro are just text replacement), you change the order of evaluation of the operation. Now BETA
is replaced by (2-1)*2
which is equal to 2.