What is an lvalue?

28 Dec 2022 Balmiki Mandal 0 C Programming

Understanding lvalues and rvalues in C programming

In programming, an lvalue (locator value) is an expression that denotes an object that has an identifiable location in memory. Lvalues can be used on the left-hand side of an assignment operator, which means that they can be assigned a value.

Some examples of lvalues in C and C++ are:

  • Variable names
  • Array elements
  • Pointers to objects
  • Function calls that return lvalue references

The following are not lvalues:

  • Constants
  • Expressions that evaluate to a function call
  • Expressions that evaluate to a temporary object

The term lvalue comes from the fact that lvalues can be used to "locate" an object in memory. For example, the expression int i = 10; defines the variable i as an lvalue, because it can be used to locate the object i in memory.

Lvalues are an important concept in programming, because they allow us to manipulate the values of objects in memory. For example, the following code assigns the value 10 to the variable i:

C Programming
int i = 10;

The i on the left-hand side of the assignment operator is an lvalue, because it denotes the object i in memory. The 10 on the right-hand side of the assignment operator is an rvalue, because it is a literal value that does not have an identifiable location in memory.

 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.