simple ques operator precedence

Hi

I was reviewing precedence order way back and I couldn't remember/understand why the following expression yielded the result it has:

1
2
3
 
x = 5 + (7 % 2);  //x = 6


why 6?

thx
Last edited on
7%2 gives 1.

5+1 gives 6.
(7 % 2); // yields 1
therefore:
x = 5 + 1; //x = 6

C++ Operator Precedence: http://en.cppreference.com/w/cpp/language/operator_precedence

Modulus Operator: http://stackoverflow.com/questions/12556946/how-does-the-modulus-operator-work
Last edited on
Thx, I've got the operator precedence down. The trick was reviewing the modulus operator: it required integer division that evaluated to an integer result (+ remainder). I understand now.

Thnx!
Last edited on
Topic archived. No new replies allowed.