Identifier Naming rules in C language

By | February 21, 2024

Prerequisite – C Language Introduction
In C any name is called identifier. This name can be:

1. Variable name
2. Function name
3. Enum constant name
4. Micro constant name
5. Goto label name

And, any other data type name like, 
6. Structure 
7. Union
8. Enum names or Typedef name

Token

These are following rules that should follow:

  • Rule-1:
    Name of identifier can include only alphabets, digits, and underscore.

    Valid name: 
    earth, subtraction123, addition_of_integer
    
    Invalid name:
    multiplication@, mean value, output%number
  • Rule-2:
    First character of any identifier must be either alphabet or underscore.

    Valid name: 
    earth, _subtraction123, addition_of_integer
    
    Invalid name:
    3multiplication@, 33, 10_output
  • Rule-3:
    Name of identifier can not be any keyword of C program.

    Valid name: 
    INT, FLOAT
    
    Invalid name:
    int, float, enum
  • Rule-4:
    Name of identifier cannot be global identifier.

    Valid name: 
    _NAME_, _TOTAL_
    
    Invalid name:
    _TIME_, _DATE_, _SMALL_, 
    _PASCAL_, _LINE_, _LARGE_
  • Rule-5:
    Name of identifier cannot be register Pseudo variables.
  • Rule-6:
    Name of identifier cannot be exactly same as of name of function within the scope of the function.
  • Rule-7:
    Name of identifier is case sensitive, means Int and int are two different variables.
  • Rule-8:
    Only first 32 characters are significant of identifier name. That is identifier can not have more than 32 characters in its name.
  • Rule-9:
    Name of identifier cannot be exactly same as constant name which have been declared in header file of C and you have included that header files. Also, it cannot be eaxtly same as function name or data type name that we have declared in the header of C.

If you will not follow these rules while naming of identifier, then program will not compiler, i.e., there will be compilation error.

 

Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.

Author: Mithlesh Upadhyay

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.