what are Rvalues and Lvalues in C++

135 pts.
Tags:
C++
C/C+/C# error messages
Rvalues and Lvalues
Turbo C++
Visual C++
[strong]on executing the below program i got error message like required Lvalue is missing in main function[/strong]

[strong] main() [/strong]

[strong]{[/strong]

[strong] int i;[/strong]

[strong] printf("%d",++i++); [/strong]

[strong]} [/strong]

[strong]plz tell me what are rvalues and lvalues. if there are any other values of this kind plz explain me that also[/strong]



Software/Hardware used:
Turbo c++/ visual c++

Answer Wiki

Thanks. We'll let you know when a new response is added.

L-values are expressions that refer to memory locations, and are usually variables or objects. An l-value is something that could appear on the left side of an equal sign (i.e. something that you can assign a value to).

In your case, this part:

<pre>++i++</pre>

Is somehow equivalent to this:

<pre>i++ = (i++) + 1</pre>

But it is an ilegal expression, because you cannot assign a value to “i++”. In other words, “i++” cannot appear on the left side of an equal sign, so it is not an l-value.

So, you can do this:

<pre>++i</pre>

or this:

<pre>i++</pre>

bot not this:

<pre>++i++</pre>

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Chippy088
    i++ means to increment the variable after use ++i means to increment it before using either way, as Carlosdl says, you cannot do both in a single command.
    4,625 pointsBadges:
    report
  • Rajeshu
    thank you for your reply sir, I have one major doubt is it correct to say that a l value is a super-set of r-value
    135 pointsBadges:
    report
  • carlosdl
    "is it correct to say that a l value is a super-set of r-value" I don't think so. Rather, I would say that r-values are a superset of l-values, because all l-values are r-values, but not vice versa.
    69,175 pointsBadges:
    report
  • Rajeshu
    ya right now I got it, (up to my knowledge) r-values are values that are on the right hand side and they can be a variable (pointing a location in memory) or it can be just a value(a number or character) but only a variable pointing to the memory location can be a l-value thank you sir, for your kind reply
    135 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following