Monday, July 30, 2012

lvalue and rvalue in c

In c
lvalue are reference to memory their value persist even after execution of statement. lvalue are mainly identifier, variables which can be on both sides of '='  assignment operator.

whereas rvalue are the value(result) of the expression,it's value is persist just for a statement execution,  rvalue (value, r optional) can only be on right side of '=' assignment operator

for example


1. int x=6;


here x is lvalue and 6 is rvalue.


2. int x=x+y+z;


x- lvalue and (x+y+z) is rvalue.


3. x+5=y+z


its and error because left operand must be lvalue but given is rvalue.


4. Also contact variable are rvalue so following expression is illegal


int const x=6;
x=7;






No comments:

Post a Comment