Hey all, I know this is a newb question here but I'm having trouble finding the answer to this equation posed in one of my past year exam scripts.
Code:
int z, x = 5, y = -10, a = 4, b = 2;
//x = 5
//y = -10
//a = 4
//b = 2
z = x++ - --y * b / a;
When I solve this equation I get an answer of 0 (zero) but when I put it in the compiler, the value returned is 10.
Heres how I solved it:
z = x++ - (--y) * b / a;
z = 5++ - (--(-10)) * 2 / 4;
z = 6 - (-11) * 2 / 4;
z = 6 - (-11) * 0 // at this point 2/4 yields 0 correct?
z = 6 + 11 * 0
z = 0;
but I am sadly mistaken as the answer is 10 according to the compiler.
Can any one help me out here?
Please and thank you. Any feedback is greatly appreciated.