Friday, 16 September 2011

Episode 2 : Variable, Data Type


Variable Declaration

After designing suitable variable names, we must declare them to the compiler. Declaration does two things:

1.     It tells the compiler what variable name is.
2.     It specifies what type of data the variable will hold.

The declaration of variables must be done before they are used in the program.

The syntax for declaring a variable is as follows :

                   data_type data_name;
                   int a;
‘a’ is the name of variable and ‘int’ is the type of data. A declaration statement must end with a semicolon.

We can declare multiple data with same data type. The syntax for multiple declaring variable is as follows:

          data_type data_name_1, data_name_2,…….,data_name_n;
          int a, b, c;
Here, variables are separated by commas and end with semicolon.

Here some declaration of variable are given bellow :

We can also use the word for variable declaration. Like this :
          int amount;
          float balance;
          char name;
          double curren_balance;
          long int shojib, digital;

No comments:

Post a Comment