Rules for naming Variables and Constants in C
Notes:
Rules for naming Variables and Constants in C programming language
1. Variable name and constant name must be meaningful and descriptive
2. Keywords should never be used as variable name or constant name
3. The first character can be an alphabet, or underscore
4. The first character should not be a number
5. All succeeding characters can be alphabets, digits, or underscores
6. No special characters are allowed except an underscore, not even space
7. Variable names and constant names are case sensitive
8. White space is not allowed
9. Use Camel case naming convention for naming variables
i.e. if there is a single word in a variable name, then all characters should be in lower case, and if there are more than one words in a variable name, then first word’s all characters should be in lower case and all succeeding words first character should be in upper case.
10. Whereas while naming a constant, all characters should be in upper case, if there are more than one word in a constant name, then they should be separated by an underscore character.
11. No two variables or constants should have same name in the same scope
12. Always initialize a variable and constant, when they are declared
Ex:
Valid: s, p, Num, num, score, playerScore, _flag, player9, _itemPrice, SCREEN_WIDTH, etc.
Invalid: 9thplayer, continue, while, for, etc.