first result: 5 second result: 1
#include <stdio.h>
/* Puzzle E18 -- precedence of arithmetic operators */
int main()
{
int a = 5, b = 10 ;
int result;
result = a + a / b;
printf("first result: %d\n", result );
result = (a + a) / b;
printf("second result: %d\n", result );
return 0;
}
For the first result, the high-precidence / is done first, yielding an int 0.
Then the value of a is added to that.
For the second result, the () force (a + a) to be done first, yielding an int 10.
Then then that is divided by the value of b.