#include<iostream>
using namespace std;
int main()
{
int i=2;
cout<<++i<<" "<<++i;
return 0;
}
Why the output of program is ‘4 4’ not ‘3 4’ ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
because both increments occur before the line is output. the actual writing to the screen is delayed until the entire line has been run, but by then the reference for i has already had its value updated.
if you split your cout line into two discrete outputs, things would evaluate as you expect.