Okay, I have a simple problem. I want to print the value of N twice and then increase it (this is just a chunk of a bigger program, ie the one in which it makes sense to do that), however, the output is "1 0".
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
int n = 0;
cout<<n<<" "<<n++<<endl;
int asdf;
cin>>asdf;
}
Now, if after reading the code the output isn't strange to you then my understanding of C++ is probably very wrong and I'm missing something obvious.
If it is, then someone please explain why it does that, because as far as I know, it should first print the value of N, which is 0, print it again, which is also 0 and then it should increase the value of N.
Yes, I know, I could've just made it look like
cout<<n<<" "<<n<<endl;
n++;
but I'm wondering why the first way of doing it wont work.
Thanks in advance
EDIT: Oh and sorry if this has been asked already, I just didn't know what to search for when I've encountered the problem