When you create a variable, you should always give a meaningful name to the variable. And follow the below rules for naming the variable:
- Variable name must not start with a digit.
- The variable name can consist of alphabets, digits, and special symbols like underscore
_
. - Blank or spaces are not allowed in the variable name.
- Keywords are not allowed as a variable name.
- Upper and lower case names are treated as different, as C is case-sensitive, so it is suggested to keep the variable names in lower case.
Let’s see a few examples for incorrect names as per the above rules:
int 1var; // incorrect - should not start with number
int var1; // correct
int my$var // incorrect - special characters not allowed
int my_var1; // correct
int my var; // incorrect - spaces not allowed
char else; // can't use Keywords
int count; // valid variable name
int Count; // new variable
int COUNT; // new variable