0

take a look on this code

#include <iostream> using namespace std; int main() { int a=1; int b=3; int sum = a + b; cout << sum,"\nhello world"; return 0; } it prints 4 not 4 hello world

18th Oct 2018, 11:48 AM
Shubham Maurya
Shubham Maurya - avatar
4 Respostas
+ 3
put << between sum and text
18th Oct 2018, 11:58 AM
1704086_ibnul
1704086_ibnul - avatar
+ 5
Taste the comma is an operator used to separate statements/expressions. There are two statements: cout << sum and: "\nhello world" with the comma between them. The second doesn't have any effect as the result wasn't stored.
18th Oct 2018, 1:12 PM
John Wells
John Wells - avatar
+ 2
replace , with << i'm not sure whats going on here i thought it wont compile or runtime exception thrown, but its not.
18th Oct 2018, 12:18 PM
Taste
Taste - avatar
+ 2
thanks for cooperation
20th Oct 2018, 7:26 AM
Shubham Maurya
Shubham Maurya - avatar