0

I have found many definitions/explanations for the terms Lvalue and Rvalue in C++, but they are quite abstract and it is not easy to apply them. One of the definitions I found (and which is more accessible) is the following one:

(both from tutorialspoint)

  • An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).

and

  • An lvalue has an address that your program can access. Examples of lvalue expressions include variable names, including const variables, array elements, function calls that return an lvalue reference, bit-fields, unions, and class members.

My questions are:

  • How can one recognize whether an object in C++ has an address?
  • Is there an example of an object which looks like an Lvalue but is not an Lvalue?
  • Is it possible to give a list of examples of Lvalues in C++ which is as complete as possible or which covers at least the most important examples of Lvalues?
  • The dichotomy of `lvalue` and `rvalue` is something from C++98. Modern C++ defines 5 value categories, as explained here: https://en.cppreference.com/w/cpp/language/value_category Those are quite nuanced, to be fair. For C++ beginners, though, a simple litmus test of "lvalue is something which can be found on both Left side and right side of assignment operator", and "rvalue is something which can only appear on the Right side". This will not be 100% correct, but should be suitable for learning. – SergeyA Oct 26 '21 at 14:22
  • 1
    objects don't have a value category, expressions do – Caleth Oct 26 '21 at 14:26

0 Answers0