Declarations of Variables

Declarations of Variables

     All variables present in the problem must be declared before it is used. This is done with the help of declaration statement. The general form is

Data-type variable list;
                       Where,
                                  Data-type            -              valid data type such as int, char etc.
                                  Variable unit        -              list of variable separated by comma.


Example:              
               
          Int  a, b, c;
This declares a, b and c as integer variables and allocate memory space.

Use of declaration:

i.                     It gives name to memory location
ii.                   It allocates memory space
iii.                  It gives the types of data

Giving Values to variables:
               
        Giving values to already declared variables is called assigning values to variables.  this is done with the help of assignment operator (=). The general form is

Variable name  =             value;

Example:

1.                   X     =             20;
2.                   PI    =             3.14;

Initializing variable:
The process of assigning initial values to variables is called initializing variables. This is done at the time of declaration. the general form is

Data-type variable = initial value;

Example:
1.       Int  a11                 =             100;
2.       Char sex               =             ‘F’;
3.       Double pay         =             80.32;
4.       Int a, b                  =             20;

No comments:

Post a Comment

Creating Objects

Creating Objects                  Creating objects means to allocate memory space for all the instance variables of the objects. S...