Why this sucks?
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 1;
int c = 1;
cout << a/(b*c);
}
|
this prints 0.
Which means that it must have calculated it like this: a/b*c instead of: a/(b*c)
Why C++ works like this? Ignoring arithmetic brackets?
b * c = 1
a / 1 = 0
0 / 1 = 0
It's doing exactly what you told it to
Topic archived. No new replies allowed.