LValues and RValues


LValues and RValues

In C, there are two types of expressions.

  • lvalue Expressions: The ones referring to a memory location are known as "lvalue" expressions. An lvalue can be found on either the left or right side of an assignment.
  • LValues Example:

    #include<stdio.h> #include<conio.h> void main() { int a; 20=a; /* [Error] lvalue required as left operand of assignment */ printf("%d",a); getch(); }

    output:

    [Error] lvalue required as left operand of assignment
  • • rvalue Expression: The term rvalue refers to a data value that is stored in memory at a specific address. An rvalue is an expression that cannot have a value assigned to it, therefore it can exist on the right-hand side of an assignment but not on the left-hand side.
  • RValues Example:

    #include<stdio.h> #include<conio.h> void main() { int a; a=20; /* Rvalue */ printf("%d",a); getch(); }

    output:

    20

Variables are lvalues, therefore they can appear on the assignment's left side. Because numeric literals are rvalues, they can't be assigned and can't be used on the left side.