I am new to this site and I don't know where to look for this particular type of problem. I am not taking a course and was just playing around with Visual Studio, some code and ran into this problem. Can someone help me with the following:
#include<iostream>
using namespace std;
int main()
{
int v = 0;
int w = 0;
cout << v << v++ << endl;
cout << w;
cout << w++;
cout << endl;
//Testing with something else.
cout << "Hello " << "there." << endl;
cout << "Hello ";
cout << "there.";
cout << endl;
return 0;
}
The following should be the same right?
cout << v << v++ << endl;
cout << w;
cout << w++;
cout << endl;
The first line should print out "00" since the first number is what v has been assigned and the following number is what appears with v++ (v has been incremented by 1 but since its post we cannot see it just yet). Yet I get "10". When I work with the lines that involve w (which should work the same due to the same initialized value), I get "00", which is about right. Shouldn't the lines be the same? When I work with the code following the comment, which is similar to the code involving v and w
//Testing with something else.
cout << "Hello " << "there." << endl;
cout << "Hello ";
cout << "there.";
cout << endl;
I get "Hello there." and "Hello there.". Identical.
Is there something obvious that I am missing?
Many thanks,
David