135 pts.
 what are Rvalues and Lvalues in 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++
ASKED: September 3, 2010  12:51 PM
UPDATED: September 21, 2010  12:38 PM

Answer Wiki:
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>
Last Wiki Answer Submitted:  September 6, 2010  2:28 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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 pts.

 

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 pts.

 

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.

 63,535 pts.

 

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 pts.