30 June 2010

lvalue and rvalue

Alsalamo Alykom,

Any variable defined in your program has two values, the "lvalue" and the "rvalue".
lvalue is the left value, and rvalue is the right value.

suppose you have defined a variable of int type:

int x;
x = 10;

in above line, you say that, save the value 10 (rvalue) in the memory location of x (lvalue).

see this example and note the difference:

int x, y;
x=10;
y=x;

first you defined two variables of type int, then in line two you say:
save the value `10` in the memory location of variable `x`, and in the third line you say: save the value in memory location `x`, into the memory location of variable `y`.
So, `x` on the left -lvalue- (at line 2) are refereed as `the address of x`, but x on the right -rvalue- (at line 3) are refereed as `the value at the address of x`.

No comments: