C identifiers
C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions, labels, etc.\
An identifier can be combination of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore.
Before starting any language, you must at least know how you name an identifier.
You cannot use keywords as identifiers; they are reserved for special use. You create an identifier by specifying it in the declaration of a variable, type, or function.
Identifiers are names given to different entities such as constants, variables, structures, functions, etc.
int amount;
double balance;
In the above example, amount and balance are identifiers and int, and double are keywords.
What are Identifiers?
Identifiers are words or texts used to identify anything in the C language.
An identifier can be combination of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore.
Before starting any language, you must at least know how you name an identifier.
Just like you have a name, using which everyone calls you, it can be John, Ron, Scarlett, Monica, etc., similarly in the C language, when we define a variable or a function, or a structure, etc.
Rules for naming identifiers
- The rules that must be followed while naming the identifiers are as follows −
- The first character of an identifier should be either an alphabet or an underscore, and then it can be followed by any of the character, digit, or underscore.
- An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
- It should not begin with any numerical digit.
- Identifier names must be unique
- In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say that identifiers are case sensitive.
- i.e.Identifiers are case-sensitive in the C language. For example, name and Name will be treated as two different identifiers.
- You cannot use a keyword as identifiers.
- Commas or blank spaces cannot be specified within an identifier.
- There is no rule on how long an identifier can be. We can run into problems in some compilers, if an identifier is longer than 31 characters. This is different for the different compilers.
- Identifiers should be written in such a way that it is meaningful, short, and easy to read.No special characters, such as a semicolon, period, whitespaces, slash, or comma are permitted to be used in or as an Identifier.
For example-
int subject;
float marks;
Here, subject and marks are identifiers.
Types of identifiers
- Internal identifier
- External identifier
Internal Identifier:
If the identifier is not used in the external linkage, then it is known as an internal identifier. The internal identifiers can be local variables.
External Identifier:
If the identifier is used in the external linkage, then it is known as an external identifier. The external identifiers can be function names, global variables.
Difference between Keyword and Identifier:
Keyword |
Identifier |
Keyword is a pre-defined word. |
The identifier is a user-defined word |
Specify the type/kind of entity. |
Identify the name of a particular entity. |
It must be written in a lowercase letter. |
It can be written in both lowercase and uppercase letters. |
It always starts with a lowercase letter. |
First character can be a uppercase, lowercase letter or underscore. |
A keyword contains only alphabetical characters. |
An identifier can consist of alphabetical characters, digits and
underscores. |
Its meaning is pre-defined in the c compiler. |
Its meaning is not defined in the c compiler. |
No special symbol, punctuation is used. |
No punctuation or special symbol except ‘underscore’ is used. |
It does not contain the underscore character. |
It can contain the underscore character. |
Examples of keywords are: int, char, if, while, do, class etc. |
Examples of identifiers are: student, subject, high_speed, etc. |