A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer.
Naming Variables
The name of variable can be called identifier or variable name in a friendly way. It has to follow these rules:
- The name can contain letters, digits and the underscore but the first letter has to be a letter or the underscore. Be avoided underscore as the first letter because it can be clashed with standard system variables.
- The length of the variable name is usually 31 characters.
Declaring Variable
To declare a variable you specify its name and kind of data type it can store. The variable declaration always ends with a semicolon, for example:
int a;
char c;
float f;
int x,y,z;
The variables should be declared at the beginning lines of any block. These cannot be declared at the middle of the program or ending.
Initializing variables
You can also initialize a variable when you declare it, for example:
int count=0;
char alp='c';
float f=23.67;
Character variable value should be represented in single quotes
No comments:
Post a Comment