C Programming Variables Assignment Help


Variable is a named storage area which holds values that can be changed during program execution. Every variable has associated data type which decides the type of values it can hold. The Rules for naming variable is same as naming identifiers.

Declaration of variables

Variables must be declared before it is used in the program. Declaration of variable specifies about the name and type of value it can hold to the compiler.

Syntax for declaring variable is:

datatype variablename;


int x;

float area;

char group;

Initialization of variables

C Programming Variables Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com

Initialization means assigning value to variable during declaration otherwise garbage value to be assigned until program execution.

Syntax for Initialization of variable:

Datatype variablename=value;


int x=5;

float area=0.0;

char group=’A’;

Lvalue and Rvalue in C

L-value has expression that represents memory location. L –value is also called as locator of storage space or Left value. It can appear on left side of (=) operator. It denotes the identifier name which represents the storage location.

Expressions represents changeable locations are called "modifiable l-values." Array and const type doesnot belong to modifiable l-value. Structures and unions are modifiable l-values, must they should not have members with const attribute.

An identifier is a modifiable l-value if it refers to a memory location and if its type is arithmetic, structure, union, or pointer. For example, if ptr is a pointer to a storage region, then *ptr is a modifiable l-value that designates the storage region to which ptr points.

Any of the following C expressions can be l-value expressions:

An identifier of integer, float, pointer, structure, or union type

A subscript ([ ]) expression that does not assess to an array

A member-selection expression (-> or .)

A unary-indirection (*) expression that does not refer to an array

An l-value expression in parentheses

Examples for L-value

int x=10;

int a=10;



Here, x and a are L-values. It hold the storage location of data type int.


R-value represents the values is stored over the Lvalue or memory location. R-value can appear right hand side of (=) operator.

L-values can act as R-values, but the reverse is not possible.

Example for L-value and R-value

int x;


int y;

y=x; //Lvalue x act as Rvalue


In this example x and y are Lvalues which hold memory location of integer data type. y=x is valid.


int z;


int r;

5=r; //Rvalue should not act as Lvalue


In the above example, z and rare name of storage locations. ‘5’ is expression which indicates R-value. 5=r is invalid.