Rules to define a variable name:
- Variable is combination of alphabet , Numbers and Special symbol.
- Name of variable must start with alphabet.
- Maximum 8 alphabets can be used in variable name.
- No blank space is used in between two characters.
- Can not define two variables of same name in a program.
- Keywords can not be used as variable name.
Declaration of Variables:
Variables must declared in every program.If it is not declared than compiler will generate error.
Compiler get information from variable declaration such as:
1. What is variable name?
2. What type of data used by variable?
Format: data-type variable-name ;
variable-name may be like: var1 , var2 , var3.....
Example:
int a , i , per , avg ;
float sal , cur ;
double ab , sp , p , cp ;
char fname , lname ;
Variable name may be any but must follow above given rules. It is good habit to use meaningful variable name according to your program.If we use appropriate variable name than identity of variable name is easy. For example if find average then use avg variable name.
I hope you understand what is variable? How we define variables? What is the use of variable in programs?.
No comments:
Post a Comment