My text wants me to predict what the value of x is after the statements are executed. The answer in the back gives 2.8; however, when I test it on my computer I don't get the same results.
double a=3.8,x;
int n=2, y;
x = (y = a/n)*2;
Heres my train of thought when doing it by hand.
First take the brackets.
So n is converted from an into to a double, but y is an int so y= 2?
Then multiply 2 and 2 to 4?
This train of thought is wrong, but I thought it would help in helping me find out what I'm doing wrong.
Thanks =D
Like I said, it truncates. So yes, it always rounds down. Yes, I think your book is wrong; I worked it out in my head as I did above and tested it on MSVC++2008, both give x == 2 after the operations.