+ 1
Arithmetic cout like cout << 2+2; prints 4 in Visual Studio, but does not print anything in gcc compiler. Why ?
In C++, cout for basic arithmetic operations gives out result directly, but it is not in GCC 5.4.0.
9 Respuestas
+ 9
https://code.sololearn.com/cOx2SMSZBtYj/?ref=app
works fine here too.
+ 6
From the observations posted here, I think it has to do with how the compiler handles the operator precedence.
It most probably evaluated (cout << 2) and then added 2 to the cout object. (But this should not have compiled properly... )
Observe what happens when you do:
cout << cout;
I might need you to try what happens when you do:
cout << (cout << 2 + 2);
+ 6
I just tried to run cout << 2+2; on an online compiler with GCC 5.4.0, and it gave me 4, so I'm not sure what is causing the issue on your side.
+ 1
http://en.cppreference.com/w/cpp/language/operator_precedence
This is an error in gcc.
+ 1
This was due to our connection. Now it outputs 4.
0
With () braces, it works. Strange...
0
Nope, still with () too.
0
It is not showing anything.
0
In SL, there is no output.