Preview
What is a variable in C Language
A variable may be defined as a named memory location. The value of a variable can vary during the execution of a program.
Rules to name a variable in C Language
- Both digits and alphabets are allowed to name a variable.
- We can use both capital and small letters buy they are treated differently.
- First character must be an alphabet or underscore.
- Variable name can have digits after first character.
- Keyword are not allowed for variable name.
- We can’t use any special character other than underscore.
- Spaces can’t be given in variable name.
Examples of invalid variable names
1st | First character can’t be a digit. |
auto | It is a keyword of C. |
{triangle} | Special characters other than underscore are not allowed. |
student class | Variable name can’t contain a space. |
last-name | Special character other than underscore are not allowed. |
Variable Declaration
The syntax for variable declaration is <data-type> var-1,var-2,……….;
Example:
int age ;
Above statement declares a variable named number of int type.
Initialization
Initialization refers to assigning some value to a variable during declaration of variable.
Example
long a=5;
Best Books of C