Value of variable in c language

Explanation of value of a variable in c programming language by examples and questions and answers

Data which any variable keeps is known as value of variable. For example:

int a=5;

Here value of variable a is five. Name of variable always returns value of the variable.

How to assign any value to a variable:

C supports eleven type of assignment operator to assign any value to operator. Those are:

(a) = 
(b) +=
(c) -=
(d) v*=
(e) /=
(f) %=
(g)   <<=
(h) >>=
(i) |=
(j) &=
(k) ^=

In this chapter will discuss only first operator i.e. =

Assignment statement in c:

LValue: Lvalue stands for left value. In any assignment statement LValue must be a container i.e. which have ability to hold the data. In c has only one type only container and which is variable. Hence LValue must be any variable in c it cannot be a constant, function or any other data type of c. For example

#define <stdio.h>
#define max 125

struct abc{
    char *name;
    int roll;

enum {RED,BLUE};

int main(){
    int a;
    const b;

    //10=5; LValue cannot be a integer constant

    //max=20; //Lvalue cannot be a micro constant

    //b=11; Lvalue cannot be a constant variable

    //float=3.3f; Lvalue cannot be a data type

    //abc={“sachin”,5}; Lvalue cannot be a data type

    //BLUE =2; Lvalue cannot be a enum constant

    return 0;

RValue: In any assignment statement RValue must be anything which can return and constant value or it is itself a constant. RValue can be any c constants, variables, function which is returning a value etc. For example:

#define max 5
void display();
float sum();
enum {BLACK, WHITE};

int main(){
    int x=2; //RValue can be a constant.
    float y=9.0;
    const int z=x; //RValue can be a constant variable
    x=max; //RValue can be a variable.
    x=BLACK; //RValue can be a enum constant.
    y=sum();//RValue can be a function.
    y=display(); //RValue can be a function which is

   return 0;

No comments: