Header Ads Widget

Variables

    A variable  is a named location in memory that is used to hold a value. Variables can hold one value at a time. The value of variable can be changed during execution of program . It is different from constant . Constant is a value that can not be changed during execution of program.

Rules for variable names :

  •   A variable is combination of alphabets, digit and underscore.
  • First character should be alphabet.
  • No special symbol other than underscore.
  • We can not use keywords as variable names.
  • Variable names are case sensitive.
  • there is no blank space or a comma in  a variable.
Examples : D_o_B          total       area1        Area

Declaration of Variable :

The declaration of variable includes-
  • Type of variable
  • Variable name
Examples : int  x;
                    int  x,y,z,total;
                    float  sal ;
                    char grade ;
                    int int_type;

Initialization of variable :

 When a variable is declared it contains undefined value, called garbage value. We can assign some initial value to the variable at the time of declaration. Assigning a value to the variable at the time of declaration is called initialization of variable.              
                    int  x = 5;
                    float  y =3.7;
                    char ch = ' N' ;
                    int a, b, c = 10;


Post a Comment

0 Comments