A variable is a value that can change any time. It is a memory location used to store a data value. A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program. Variable names are case sensitive. Example of variable names are
Sun
number
Salary
Emp_name
average1
Any variable declared in a program should confirm to the following
1. They must always begin with a letter, although some systems permit underscore as the first character.
2. The length of a variable must not be more than 8 characters.
3. White space is not allowed and
4. A variable should not be a Keyword
5. It should not contain any special characters.
Examples of Invalid Variable names are
123
(area)
6th
%abc
Declaration of Variables
Every variable used in the program should be declared to the compiler. The declaration does two things.
Tells the compiler the variables name.
Specifies what type of data the variable will hold.
The general format of any declaration
datatype v1, v2, v3, ……….. vn;
Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration statement must end with a semicolon.
Example:
Int sum;
Int number, salary;
Double average, mean;