4 ms·
Terrible start point: An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address). rvalues are def
by jpdoctor 15y ago
Terrible start point:
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
rvalues are defined by exclusion, by saying that every expression is either an lvalue or an rvalue.
So a pointer represents "an object that occupies some identifiable location in memory", meeting his definition of lvalue, and yet is a perfectly valid rvalue.
I sentence this person to be a teaching assistant for one term.
Edit: I love the first two replies to this comment:
1. No, lvalues are never rvalues by definition.
2. all lvalues are rvalues,
- tedunangst 15y agoall lvalues are rvalues, so yes, an lvalue is a perfectly valid rvalue. oh, maybe you meant an rvalue that happens to be a pointer? still makes sense, the pointer is not the same as what it points to. [In light of Sharlin's comment, I should edit this to say that "lvalues are rvalues" is shorthand for "convertible to", the significance of the difference being what you make of it.]
- Sharlin 15y agoNo, lvalues are never rvalues by definition. In the C and C++ language standards, rvalues and lvalues are not defined based on which side of the assignment operator they may appear on. The assignment operator takes an rvalue as its right operand, however, lvalues are also accepted there because there's an implicit lvalue-to-rvalue conversion taking place, as pointed out later in the article.
- pillbug88 15y agoI find the standard to be very clear and concise regarding lvalue/xvalue/prvalue [2011 3.10.1]. I wonder if teaching from the standard is a better way of approaching this, ie: start with the standard, then just explain what it means.
- zokier 15y agoYes, many (if not all?) lvalues are (or actually could be) perfectly valid rvalues. But no value is both at the same time. There is nothing odd in having something that can be either A or B, but not both at the same time. So a pointer can be a lvalue or a rvalue. If the pointer is at a "identifiable loaction in memory" then it's a lvalue, and if it's not, then it's a rvalue.