Variable& Lvalue and Rvalue
Variable& Lvalue and Rvalue
2015
The name of a variable can be composed of letters, digits, and the underscore character. It must begin
with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive.
Variable Definition in C:
Syntax to declare a variable:
Data type variable name = value;
Data type variable name;
A variable definition means to tell the compiler where and how much to create the storage for the
variable. A variable definition specifies a data type and contains a list of one or more variables of that
type as follows:
type variable_list;
Here, type must be a valid C data type including char, int, float, double, or any user-defined data type,
etc., and variable_list may consist of one or more identifier names separated by commas. Some valid
declarations are shown here:
int i, j, k;
char c, ch;
float f, salary;
double d;
The line int i, j, k; both declares and defines the variables i, j and k; which instructs the compiler to create
variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an
equal sign followed by a constant expression as follows:
Note:
If we does not initialize the variable with some value, there will be garbage value stored in the particular
variable.
FindMind Collection
2015
1. lvalue : Expressions that refer to a memory location is called "lvalue" expression. An lvalue may appear
as either the left-hand or right-hand side of an assignment.
2. 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- but not
left-hand side of an assignment.
Variables are lvalues and so may appear on the left-hand side of an assignment. Numeric literals are
rvalues and so may not be assigned and can not appear on the left-hand side. Following is a valid
statement:
int g = 20;
But following is not a valid statement and would generate compile-time error:
10 = 20;
Rvalue:
Rvalue stands for Right Value of the expression
In any assignment statement R-value of expression must be anything which is capable of returning
constant expression or constant value.
Rvalue can be a constant, function, variable, macro.
Syntax:
Lvalue = Rvalue;
Lvalue:
Lvalue stands for Left Value of the expression
Lvalue of the expression refers to the memory locations
In any assignment statement R-value of expression must be a container (i.e must have the ability to hold
the data)
Variable is the only container in C programming thus Lvalue must be any variable.
Lvalue cannot be the constant, function or any of the available data type in C.
Syntax:
Lvalue = Rvalue.
Diagram: