Wednesday, August 12, 2015

C Variables and Rules for Variable name

Variables :-

An entity that may change is called Variable.






For example:- a=3;
                         a=5; Here the value of 'a' is changed from 3 to 5. 'a' is a variable.

1. As we know that every value store in memory at specific location.

2. If we have to call that value we should remember the location. But it is difficult to remember. So, we give that location a name which can be remember easily.

3. These name of location in memory are known as variable name.Means variable names are the names given to location in memory.

4. Values at these location can be integer, real or character constants.

5. Specific type of variable can store  the specific type of constant.

For example:- An integer variable  can only store an integer constant.
                        int a;
                        a=2;

                        An real variable  can only store an real constant.
                        float b;
                        b=5.5;

                        An character variable  can only store an character constant.
                        char c;
                        c='a';





Rules for Constructing Variable Name:-

1. Length of the variable name is depends upon the compiler type. Some compiler allows variable name's length up-to 247 character. But it would be safer to use the rule of 31 character.

2. In variable name first character must be an alphabet or underscore.

3. There is no commas or blanks are allowed within a variable name.

4. In variable name other than underscore no special symbols can be used.

5. Keywords used in C programming cannot be used as a variable name.

For example:- int simple;
                         int sim_ple;
                         int _simple;