Rules for Constructing Variable Names in C Language
A variable is an entity whose value keeps on changing throughout the program execution. As we all know, data is stored in the memory of the computer. Actually, data is not stored in the variable. A variable is the name given to the memory location. A variable name is an entity that points to a particular memory location.
Variable can be of different types.
Rules for constructing variable names
- A Variable name consists of any combination of alphabets, digits and underscores. Some compiler allows variable names whole length could be up to 247 characters. Still it would be safer to stick to the rule of 31 characters. Please avoid creating long variable name as it adds to your typing effort
- The first character of the variable name must either be alphabet or underscore. It should not start with the digit
- No commas and blanks are allowed in the variable name
- No special symbols other than underscore are allowed in the variable name
We need to declare the type of the variable name before making use of that name in the program. Type declaration can be done as follows:
To declare a variable as integer, follow the below syntax:
Here int is the type of the variable named variable_name. ‘int’ denotes integer type.
Following are the examples of type declaration statements:
int p, n;