Identifier refers to name given to entities such as variables, functions, structures etc.
The identifier must be unique. They are created to give a unique name to an entity to identify it during the execution of the program. For example:
Here, money and accountBalance are identifiers.
Also remember, identifier names must be different from keywords. You cannot use
int as an identifier because
int is a keyword.
Rules for writing an identifier
- A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.
- The first letter of an identifier should be either a letter or an underscore. However, it is discouraged to start an identifier name with an underscore.
- There is no rule on length of an identifier. However, the first 31 characters of identifiers are discriminated by the compiler.
- They must not begin with a digit.
- Commas or blank spaces are not allowed within an identifier.
- Keywords cannot be used as an identifier.
- Identifiers should not be of length more than 31 characters.
Following are the list of valid and invalid identifiers:
total, sum, average, _x, y_, mark_1, x1, etc.
1x – begins with a digit
char – reserved word
x+y – special character
Types of Identifiers
C defines two kinds of Identifiers:
- External Identifiers
- Internal Identifiers
If the identifier is used in an external link process, then it is called as external. These identifiers are also known as external names; include function names and global variable names that are shared between source files. It has at least 63 significant characters.
If the identifier is not used in an external link process, then it is called as internal. These identifiers are also known as internal names; includes the names of local variables. It has at least 31 significant characters.