Identifiers in C language | Rulers for naming Identifiers in C language
Introduction:
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
- Identifiers
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.
Keywords examples:
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:
- joey
- _Mick
- Ronaldo10
- Learn_C_Programming_31
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.
Quick Notes:
- 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.
Conclusion:
In this article, We looked at the Identifiers and Rules to name the Identifiers in C programming Language.
7 Responses
[…] 📢. There are few rules which we need to follow while naming the identifiers, We have discussed about those rules in the following article, Please check for more info – Identifiers in C language | Rulers for defining Identifiers in C language – SillyCodes […]
[…] have discussed about the Identifier in C and rules for naming the Identifiers in our Previous article, In today’s article, We will learn about the Variables in C […]
[…] Here the LABEL is an Identifier, you can use any valid Identifier here. Make sure you follow the Identifiers naming rules. […]
[…] The name of the user-defined function. Can be any C Identifier. […]
[…] Prompt the user to provide the desired Row size and Column Size, and store them in the variables rows and columns respectively. (Note, These rows and columns are small letters – C is Case Sensitive language) […]
[…] Prompt the user to provide the desired Row size and Column Size for First Matrix i.e X, and store them in the variables rows1 and columns1 respectively. (Note, These rows and columns are small letters – C is Case Sensitive language) […]
[…] is the name of the […]