473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why does assignment operator return lvalue?

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
1 3365
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Matthew Polder | last post by:
Hi, When a class Apple is written and the assignment operator is not explicitly declared, the operator Apple& operator=(const Apple&) is created by the compiler. Is there any difference...
47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
18
by: Daniel Billingsley | last post by:
Or seem to anyway. ===== string abc; if ((abc=getString()) != "") { MessageBox.Show(abc); } private string getString() {
77
by: berns | last post by:
Hi All, A coworker and I have been debating the 'correct' expectation of evaluation for the phrase a = b = c. Two different versions of GCC ended up compiling this as b = c; a = b and the other...
12
by: subramanian100in | last post by:
For a class Test, we write the assignment operator as Test & Test::operator=(const Test & rhs); instead of const Test & Test::operator=(const Test & rhs); that is, the return type of...
7
by: Rahul | last post by:
Hi Everyone, I was overloading the operator= function as a class member function, #include <iostream.h> class A { int value; public : A& operator = (const A& ref)
1
by: subramanian100in | last post by:
Consider the following: int x; int y; int z; (x+y) = z; For this statement, I get the following error with g++ compiler: error: non-lvalue in assignment Suppose I have a class Test and x,...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Anyone know of any way to get a reference to the argument to the left (lvalue I believe it is called) of the assignment operator? I realize you can't overload the assignment operator in C#, but...
11
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.