Friday, 24 February 2017

Lvalues and Rvalues in C

Lvalues and Rvalues in C

There are two kinds of expressions in C:

· lvalue : Expressions that refer to a memory location are called "lvalue"
expressions. An lvalue may appear as either the left-hand or right-hand
side of an assignment.

· rvalue : The term rvalue refers to a data value that is stored at some
address in memory. An rvalue is an expression that cannot have a value
assigned to it which means an rvalue may appear on the right-hand side
but not on the left-hand side of an assignment.

Variables are lvalues and so they may appear on the left-hand side of an
assignment. Numeric literals are rvalues and so they may not be assigned and
cannot appear on the left-hand side. Take a look at the following valid and
invalid statements:


int       g = 20;           // valid statement
10 = 20;                      // invalid statement; would generate compile-time error

No comments:

Post a Comment