+ 6
Basic operation on cout
for (int m=0;m<3;++m) { cout << m%2?m:m+2; } why output of this code is 010 ?
9 ответов
+ 11
The reason why you got 010 instead of 214 is because the statement was evaluated as:
(cout << m%2)?m:m+2;
instead of
cout << (m%2?m:m+2);
http://en.cppreference.com/w/cpp/language/operator_precedence
+ 4
It seems that c++ just looks at m%2 if you don't put the whole block in parentheses:
cout << (m%2?m:m+2)
+ 3
Rahul George 214 is correct:
m = 0 -> false -> m+2 = 2
m = 1 -> true -> 1
m = 2 -> 2%2=0 -> false -> m+2 = 4
+ 1
No paranthesis changes precedence level. Modulus has highest precedence and will do it first.
0
endoo emo
0
thanks to all
0
214
0
in c++ how can i solve if a problem can make?
0
то