22.01.2019, 06:42
Quote:
Hello sampers, I was wondering what's the difference between "#define something 5" and "#define something (5)"?
|
PHP Code:
#define EIGHT_PLUS_TWO 8+2
PHP Code:
#define EIGHT_PLUS_TWO (8+2)
lets see the first case
PHP Code:
#define EIGHT_PLUS_TWO 8+2
main(){
new result = 2 * EIGHT_PLUS_TWO;
ASSERT(20==result);//will fail as result is 18
}
Code:
new result = 2 * EIGHT_PLUS_TWO = 2 * 8+2 = 16+2 = 18 as per operator precedence
PHP Code:
#define EIGHT_PLUS_TWO (8+2)
main(){
new result = 2 * EIGHT_PLUS_TWO;
ASSERT(20==result);//will pass as one in parentheses is evaluated first
}
Code:
result = 2 * EIGHT_PLUS_TWO = 2 * (8+2) = 2*(10) = 20 as per operator precedence