Mailinglist Archive: opensuse-programming (32 mails)
| < Previous | Next > |
post increment and self assignment problem
- From: Verdi March <cincaipatron@xxxxxxx>
- Date: Sat, 6 Jul 2002 06:31:55 +0200 (MEST)
- Message-id: <22008.1025929915@xxxxxxxxxxxxx>
Hi,
I'd like to ask a (basic) question about operator post inc (lvalue++).
I've this code fragment:
/**************/
int y = 10;
int z;
z = y++;
cout << "z = " << z << '\n';
int x = 10;
x = x++;
cout << "x = " << x << '\n';
/**************/
The execution results in:
z = 10
x = 11
I'm confused why x became 11, because the post inc. operator has
higher precedence than assignment, so given an expressoin x = x++,
x++ is evaluated first. The signature for post inc. is T operator++(int).
So the return value of x++ is 10 (x itself will be modified to 11), but
then the expression of x = (x++) become x = ret_val_of_x_plus_plus,
which is x = 10? Am I correct?
Regards,
Verdi
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
I'd like to ask a (basic) question about operator post inc (lvalue++).
I've this code fragment:
/**************/
int y = 10;
int z;
z = y++;
cout << "z = " << z << '\n';
int x = 10;
x = x++;
cout << "x = " << x << '\n';
/**************/
The execution results in:
z = 10
x = 11
I'm confused why x became 11, because the post inc. operator has
higher precedence than assignment, so given an expressoin x = x++,
x++ is evaluated first. The signature for post inc. is T operator++(int).
So the return value of x++ is 10 (x itself will be modified to 11), but
then the expression of x = (x++) become x = ret_val_of_x_plus_plus,
which is x = 10? Am I correct?
Regards,
Verdi
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
| < Previous | Next > |