what is lvalue????

Dani AI

Generated

Brief, practical clarification for (and expanding on and ): an lvalue is an expression that denotes an identifiable object or storage location. An rvalue is a temporary value that does not have a persistent identity. That classical distinction explains why some expressions can appear where a store/assignment target is needed and others cannot—but C++ has evolved, so there are more precise categories now (glvalue, prvalue, xvalue) that matter for references and move semantics.

Small examples showing common rules and fixes:

int x = 1;
int &r = x;         // ok: binds to an lvalue
// int &r2 = x + 2; // error: non-const lvalue reference cannot bind to rvalue
const int &cr = x + 2; // ok: const lvalue reference can bind to rvalue
int& get_ref();
get_ref() = 10;   // valid if get_ref returns an lvalue reference to assignable storage

int make_val();
make_val() = 3;   // error: function returned a prvalue (rvalue) — not assignable

Troubleshooting notes (why compilers say "lvalue required"): common causes are trying to assign to a temporary, to a function call that returns by value, or to an expression like an arithmetic result. Remedies include assigning to a named variable, returning a reference from the function if appropriate, or changing overloads to accept const refs or rvalue refs (T&&) when move semantics are intended.

As offered a compact view and gave the classical assignment rule, this expands those points for modern C++ usage: understanding reference binding rules and the C++11+ value categories will clear up most surprises.

Recommended Answers

All 6 Replies

value on the left hand side of an expression containing assignment operator

lvalue (pronounced "ell-value"): An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment.

rvalue (pronounced "are-value"): An expression that is an rvalue may appear on the right- but not left-hand side of an assignment.

for example :

let say a and b are integer variables
you can type something like this :
a = a + b;
but cant type
a + b = a; because arithmetic expression can not be an lvalue.
or you cant say "abc" = "abcd" because literal constant can not be an lvalue.

> What is a search engine?
I suppose I can add "what is a gravedigger?" as well, to the bump of the long-dead thread.

> What is a search engine?
I suppose I can add "what is a gravedigger?" as well, to the bump of the long-dead thread.

if a question is not resolved that means it is not long-dead. if you search google with lvalue you come accross to this thread, i added this because i didnt want people to think that daniweb is weak solving problems. anyway what i do is something that has to be appreciated, if google returns results about these entries that means that these threads does not dead until they are resolved.

Thank you for your assistance. I just found this thread on Google as the second result, and it was immensely helpful. Thank you to those that took time to answer the question, and to those that replied with sarcasm and attitude: why waste your time and ours with such a useless response?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.