lvalue Required
Can anyone tell me in simple words that what this L value is and why I'm coming开发者_JS百科 across the error "L Value required in function main()"?
Lvalue is something which can be assigned to, or taken a pointer of.
It's something that has an address.
Example:
int f()
{
return 5;
}
f() = 8; // doesn't compile, f() is not an lvalue
int* g()
{
int* pv = malloc(sizeof(int));
*pv = 5;
return pv;
}
*g() = 8; // compiles, as *g() is a lvalue
If you post your code, we will be able to tell you why are you getting the error message about the missing lvalue.
An lvalue is a term given to an expression that refers to an object, i.e. something with an address.
Historically it comes from the the fact that it's something that's valid to appear on the left of an assignment. In contrast, something that can appear on the right of an assignment is known was an rvalue, however rvalue actually refers to any expression that isn't an lvalue.
Typically you can convert lvalues to rvalues (objects have a value), but not the other way around.
Usually the error that you are getting means that you are trying to do something to an rvalue that is only valid for lvalues.
That might be, assigning to the result of a function, or taking the address of a literal.
f() = 5;
int *p = &5;
精彩评论