What is an lvalue?

An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.  

Showing Answers 1 - 12 of 12 Answers

vinaysena

  • May 6th, 2006
 

can u guys plz provide me an example?

Syam Prasad N

  • Jul 13th, 2006
 

example to demonstrate lvalue

#define CONSTANT_VAR 10

int var=1;

int* pntr_int=5;

CONSTANT_VAR = 15;

The variable var is an integer, which is a storable location in memory. Therefore, the statement var = 1 qualifies var to be an lvalue. Notice the second assignment statement, *pntr_int = 5. By using the * modifier to reference the area of memory that pntr_int points to, *pntr_int is qualified as an lvalue.

 In contrast, observe the CONSTANT variable:

 In this statements, the left side of the statement evaluates to a constant value that cannot be changed because constants do not represent storable locations in memory. Therefore, this assignment statements do not contain lvalues and will be flagged by your compiler as errors.

khalil Ahmad

  • Apr 13th, 2007
 

lvalue is variable or you can say a memory location which can store (predefined type) rvalue while rvalue is constant

  Was this answer useful?  Yes

eyehz

  • May 14th, 2007
 

lvalue is an expression that referes to a memory location or object. However, it is not necessary to appear on the left side of equation. For example:

int x = 2;
int *y;
y = &x;

Notice the assignment in line 3, since we declared y as a pointer to integer, the right side value must be a lvalue, ie. &x is a lvalue that points to a memory location and match the requirements of the y declaration. But the following statement would be wrong:

y=x

because x is not a lvalue.

  Was this answer useful?  Yes

Judd

  • May 17th, 2007
 

however, that is not entirely correct, because both of these statements are valid:
y = NULL
y = 0;

  Was this answer useful?  Yes

anand

  • Jul 5th, 2007
 

A lvalue is simply the address value, where, the value assigned to a variable is to be stored. 

  Was this answer useful?  Yes

Bharath B.G.

  • Jul 24th, 2007
 

lvalue is the starting address of a data object(any variable). rvalue is the value stored in that location.

  Was this answer useful?  Yes

vinayak

  • Jul 25th, 2007
 

lvalue of a assignement statement is always a variable it cant be expr. Assignement is storing of rvalue into it. lvalue of cond statement can be expr

  Was this answer useful?  Yes

Nabhi

  • Sep 17th, 2007
 

Example for the lvalue:

consider
main()
{
    int i=5;

    now ++i++;

    first it will increament the value of i as it is preincreamnet as 6.
    now the expression looks like 6++;

    can u imigine how its possible to increament a one number in this case 6++;

    the compiler trying to find out where is the variable .... here it is a number that is why it will ask for the lvalue required.
}

i think i have cleared ur dpubt... with suitable example.... if not means just drop a mail to nabhi_jkd @ yahoo . co . in


regards
Nabhi
Techmahindra limited.

  Was this answer useful?  Yes

sadhus_01

  • Oct 20th, 2007
 

Expressions that refer to memory locations are called “l-value” expressions. An l-value represents a storage region’s “locator” value, or a “left” value, implying that it can appear on the left of the equal sign (=). L-values are often identifiers.

Expressions referring to modifiable locations are called “modifiable l-values.” A modifiable l-value cannot have an array type, an incomplete type, or a type with the const attribute. For structures and unions to be modifiable l-values, they must not have any members with the const attribute. The name of the identifier denotes a storage location, while the value of the variable is the value stored at that location.

An identifier is a modifiable l-value if it refers to a memory location and if its type is arithmetic, structure, union, or pointer. For example, if ptr is a pointer to a storage region, then *ptr is a modifiable l-value that designates the storage region to which ptr points.

Any of the following C expressions can be l-value expressions:

  • An identifier of integral, floating, pointer, structure, or union type

  • A subscript ([ ]) expression that does not evaluate to an array

  • A member-selection expression (–> or .)

  • A unary-indirection (*) expression that does not refer to an array

  • An l-value expression in parentheses

  • A const object (a nonmodifiable l-value)

rupa

  • Nov 1st, 2007
 

lvalue is an expression which refers to the memory location where the variable is stored..
eg -
          int * E = 5;

      here, *E is lvalue, which is pointing to the memory location which contains 5.
      refer  page no 197 of dennis ritchie(book - c programming language) for more details.....

  Was this answer useful?  Yes

lvalue is is a memory location,whose value is not constant i.e it's value is changed when a new value entered into that location.
And also it can be say as, it is an expression,where  left side we have an identifier and right side(rvalue) the value.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions