K
Karlo Basic
Greetings!
I'm wondering how do the expressions in the following piece of code
evaluate and why:
#include <iostream>
using namespace std;
int main()
{
int n = 5, p;
n = n + n++;
cout << "n = " << n << endl;
n = 5;
p = n + n++;
cout << "p = " << p << endl;
return 0;
}
I compiled it both with g++ and bcc32 and the results are identical:
n = 11
p = 10
The first result seems obvious. But I don't know what's going on with
the evaluation of the p variable. I am really interested on how it
works. Thank you in advance,
Karlo.
I'm wondering how do the expressions in the following piece of code
evaluate and why:
#include <iostream>
using namespace std;
int main()
{
int n = 5, p;
n = n + n++;
cout << "n = " << n << endl;
n = 5;
p = n + n++;
cout << "p = " << p << endl;
return 0;
}
I compiled it both with g++ and bcc32 and the results are identical:
n = 11
p = 10
The first result seems obvious. But I don't know what's going on with
the evaluation of the p variable. I am really interested on how it
works. Thank you in advance,
Karlo.