C++: Why does "100 x 9/5" differ from "100 x (9/5)"?
I was experimenting with some arithmetic in Bloodshed Dev C++, and I found that:
9/5 = 1, and
(9/5) = 1
This makes sense to me because you are dividing two integer data-types, which will produce a truncated integer as opposed to the "correct" answer of 1.8. However, I became confused when I got the following outputs:
100 * 9/5 = 180, and
100 * (9/5) = 100.
The operation producing "180" was the answer I was looking for, but my code normally follows the latter's format. I'm wondering as to why the brackets make a difference here.
|