Identifiers in C language | Rulers for naming Identifiers in C language
In our previous article, We have discussed about the Constants in the C programming. In this article, We will discuss about the Identifiers in C and what are the rules for creating or naming the Identifiers.
Identifiers in C Programming Language :
In C Programming language we have two types of words one are keywords and others are Identifiers.
All the words we deal with in the C programming can be classified into two types. They are.
- Keywords or Reserved words
What are Keywords or Reserved words:
The Keywords are predefined words or Reserved words in C Language. The C Compiler knows the meaning of these words. So we can’t use keywords for any other purpose.
As the keywords already have the predefined meaning, Using the same name for our other purposes will create the ambiguity for compiler. So avoid using the keyword names for any other purpose.
if, int, float, for, etc
Please look at the following article to learn more about the all Keywords in C Language – Keywords in C language | Reserved words in C language – SillyCodes
What are Identifiers in C Language:
The Identifiers in C Language are user defined words and Unknown to the C Compiler.
The Identifiers are used to name any entity like Functions, Variables, Arrays and Structures,..etc.
Identifiers is unknown words to compiler if you are going to use Identifier then you have to define it’s meaning
For example, If you are going to create Function then you need to write the function Definition. So that Compiler knows what to do with it.
📢 Every words which is not a Keyword, is an Identifier.
Okay, Now we know what are keywords and Identifiers. The C Language have few rules which we need to follow while creating or naming the Identifiers. So we need to follow these rules in-order to comply with the compiler. If you know any other programming language these rules might look very similar to you.
Rules for naming Identifiers in C Language :
- The Identifier name should contains only Alphabets(lower and upper cases), Digits and Underscore( _) characters.
- First character must be alphabet or underscore( _ ).
- First Character should not a Digit.
- The Name of an Identifier should not be a valid Keyword name.
- Identifier must be smaller than 32 characters ( Depends on Compiler Implementation).
- The C language is Case Sensitive Language. So upper case letter and lower case letters are different. That means RUSSEL and russel are completely different Identifier names.
Here are few valid and Invalid Identifier Names.
Few Valid Identifiers examples:
Few Invalid Identifiers
- 4Lewis // First character should not be digit. Violating 3rd rule from above rules.
- char // char is a valid keyword. Violating 4th rule.
- Max_# // '#' is not allowed. Violating 1st rule
- silly codes // The spaces are not allowed.
- Always give meaningful names to the Identifiers or variables. This will improve the code readability. So don’t name your Identifiers randomly.
- Try to follow same naming convention throughout the all programs. For example, If you like to use CamelCase then use camelCase for all your variable names.
- Don’t give very long names for the Identifiers or variables. Use concise and meaningful names.
In this article, We looked at the Identifiers and Rules to name the Identifiers in C programming Language.