C variable naming rules

Rules For Constructing Variable Name

  1. Characters Allowed :
    • Underscore(_)
    • Capital Letters ( A – Z )
    • Small Letters ( a – z )
    • Digits ( 0 – 9 )
  1. Blanks & Commas are not allowed
  2. No Special Symbols other than underscore(_) are allowed
  3. First Character should be alphabet or Underscore
  4. 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

Valid Names

gatepoint
Gatepoint
Gatepoint1
_GATEPOINT
GATEPOINT_temp2

Tip 2 : blanks are not allowed

Invalid Names

gatepoint 1
gatepoint 1
gate cse

Tip 3 : No special symbols other that underscore

Valid Identifier

gatepoint_1
gate_cse
new_user

Invalid Identifier

@gatepoint_1
[email protected]
new#user

Tip 4 : First Character must be underscore or Alphabet

Valid Identifier

_gatepoint
Gatepoint
Gatepoint_
_
__

Invalid Identifier

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)

Valid Identifier

iNt
Char
Continue
CONTINUE

Invalid Identifier

int
char
continue

Remember following Tricks

  1. Do not Create unnecessarily long variable name
  2. Do not use underscore as first character to avoid confusion between System Variable & user defined variables because many system variables starts with undescore
  3. Variable names are case-Sensitive . i.e sum,Sum,SUM these all three are different variable names.
  4. Reserve words with one/more Capital letters allowed eg. Int,Float,chAr are allowed but try to skip them.

Leave a Reply

Your email address will not be published. Required fields are marked *