Apr 9, 2016 at 8:00pm Apr 9, 2016 at 8:00pm UTC
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 Apr 9, 2016 at 8:00pm Apr 9, 2016 at 8:00pm UTC
Apr 9, 2016 at 8:05pm Apr 9, 2016 at 8:05pm UTC
7%2 gives 1.
5+1 gives 6.
Apr 9, 2016 at 8:08pm Apr 9, 2016 at 8:08pm UTC
Last edited on Apr 9, 2016 at 8:13pm Apr 9, 2016 at 8:13pm UTC
Apr 9, 2016 at 8:25pm Apr 9, 2016 at 8:25pm UTC
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 Apr 9, 2016 at 8:28pm Apr 9, 2016 at 8:28pm UTC