Rules For Constructing Variable Name
- Characters Allowed :
- Capital Letters ( A – Z )
- Small Letters ( a – z )
- Digits ( 0 – 9 )
- Blanks & Commas are not allowed
- No Special Symbols other than underscore(_) are allowed
- First Character should be alphabet or Underscore
- Variable name Should not be Reserved Word
- All variable names must begin with a letter of the alphabet or an underscore( _ ). For beginning programmers, it may be easier to begin all variable names with a letter of the alphabet.
- After the first initial letter, variable names can also contain letters and numbers. No spaces or special characters, however, are allowed.
- Uppercase characters are distinct from lowercase characters. Using all uppercase letters is used primarily to identify constant variables.
- You cannot use a C/C++ keyword (reserved word) as a variable name.
Explanation with Example
Tip 1 : Use allowed Characters
gatepoint Gatepoint Gatepoint1 _GATEPOINT GATEPOINT_temp2
Tip 2 : blanks are not allowed
gatepoint 1 gatepoint 1 gate cse
Tip 3 : No special symbols other that underscore
gatepoint_1 gate_cse new_user
@gatepoint_1 [email protected] new#user
Tip 4 : First Character must be underscore or Alphabet
_gatepoint Gatepoint Gatepoint_ _ __
1gatepoint 1_gatepoint 365_days
Tip 5 : Reserve words are not allowed
- C is case sensitive.
- Variable name should not be Reserve word.
- However you can capitalize first letter of reserve word and you can use it. (But try to avoid)
iNt Char Continue CONTINUE
int char continue
Remember following Tricks
- Do not Create unnecessarily long variable name
- Do not use underscore as first character to avoid confusion between System Variable & user defined variables because many system variables starts with undescore
- Variable names are case-Sensitive . i.e sum,Sum,SUM these all three are different variable names.
- Reserve words with one/more Capital letters allowed eg. Int,Float,chAr are allowed but try to skip them.