Variables can be seen as value container that will store value assigned to the variable.
So if we want to keep some value preserved and want to use later, we would use variable.
Syntax of declaring variable is :
<datatype> <variable_1>, <variable_2>, <variable_3>......, <variable_N>;
Rules for declaring variable name :
- Variable name can only contain alphanumberic (a-z, A-Z, 0-9) and underscore ( _ ) characters
- Variable name can't start with digit. So '9mark' is invalid variable name.
- Variable name is case sensitive. So 'number' and 'Number' are two different variables
Example declaration :
Here 'int' is datatype and 'number' is variable name. 'number' is variable of type integer.
long marks, total;
Here 'long' is datatype and 'marks' and 'total' are variable name. 'marks' and 'total' are variable of type long integer.
Here 'char' is datatype and 'ch10' is variable name. 'ch10' is variable of type character.
Constants are values or identifiers whose value can't be changed during whole program.