+ 2
The weird result
Why does the following code outputs 8: #include <iostream> using namespace std; int main() { cout<< 3/3+7; return 0; }
7 Respostas
+ 24
3/3=1
1+7=8
operations like */% are carried out before +-
+ 20
8
+ 14
3/3+7 ->
1+7 ->
8
(operations on left are executed first)
+ 8
/ has higher precedence than + . So 3/3=1 and 1+7= 8.
+ 4
Ok but why
+ 4
I should have thought about it..Thanks
+ 4
BODMAS Rule comes into picture
(Brackets of division, multiplication, addition, subtraction)