By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Why does assignment operator return lvalue?

P: n/a
In C++, why does assignment operator always return a lvalue. Even in
cases of assignment of basic datatypes like int ?

For eg.

int main()
{
int a, b, c;
a = b + c;
return 0;
}

Here, in the above example the assigment returns an lvalue in C++,
whereas in C it would be a rvalue.
Is it a C++ standard ? If yes, then what is the logic behind doing such
a thing????

Apr 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Tapeesh" <ta*****@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com
In C++, why does assignment operator always return a lvalue. Even in
cases of assignment of basic datatypes like int ?

For eg.

int main()
{
int a, b, c;
a = b + c;
return 0;
}

Here, in the above example the assigment returns an lvalue in C++,
whereas in C it would be a rvalue.
Is it a C++ standard ?
Yes. Section 5.17/2 of the C++ Standard says:

"There are several assignment operators, all of which group right-to-left.
All require a modifiable lvalue as their left operand, and the type of an
assignment expression is that of its left operand. The result of the
assignment operation is the value stored in the left operand after the
assignment has taken place; the result is an lvalue."
If yes, then what is the logic behind doing such a thing????


See here, especially the comment of Andrew Koenig

http://www.codecomments.com/archive3...-4-445127.html

--
John Carson
Apr 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.