An identifier is a collection of characters which acts as the name of variable, function, array, pointer, structure, etc…
Keywords are used along with identifiers to define them. Keywords explain the functionality of the identifiers to the compiler.
int student; float marks;
In above example student and marks are identifiers.
Rules for constructing C identifiers
- It should not begin with any numerical digit.
- 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 contain letters (UPPERCASE and lowercase), numerics & underscore symbol only.
- Identifiers are case sensitive. For example “name” and “Name” both are different.
- Commas or blank spaces cannot be specified within an identifier.
- Keywords cannot be represented as an identifier. You cannot use keywords like
whileetc. as identifiers.
- Only underscore symbol is allowed. No special characters, such as a semicolon, period, whitespaces, slash, or comma are permitted to be used in or as an Identifier.
- There is no rule on how long an identifier can be. However, you may run into problems in some compilers if the identifier is longer than 31 characters. This is different for the different compilers.
- An identifier must be unique in its scope.
- Identifiers should be written in such a way that it is meaningful, short and easy to read.
Example of valid identifiers
total, sum, average, _m _, sum_1, etc.
Example of invalid identifiers
2sum (starts with a numerical digit) int (reserved word) char (reserved word) m+n (special character, i.e., '+')
Differences between Keyword and Identifier
|Keywords are pre-defined.||The identifiers are user-defined.|
|It must be written in lowercase letters.||It can be written in both lowercase and uppercase letters.|
|Its meaning and functionality is pre-defined in the C compiler.||Its meaning and functionality is not defined in the C compiler.|
|It is a combination of alphabetical characters.||It is a combination of alphanumeric characters.|
|Also known as reserved words.||Also known as user defined names.|
|It does not contain the underscore character.||It can contain the underscore character.|