Identifiers in C are names given to various entities such as variables, functions, arrays, structures, unions, labels, etc. . An identifier is a combination of alphanumeric characters, i.e., it can contain letters (both uppercase and lowercase letters), digits, and underscores. The first character of an identifier should be either a letter or an underscore. Identifiers must be unique, and they are created to give a unique name to an entity to identify it during the execution of the program. Some predefined words are already written in the programming language, which is called keywords, and we cannot use these keywords as our identifiers because they are already reserved and have a special meaning in the programming language. Hence, it is not possible for the compiler to use two different entities with the same name.
Rules for naming identifiers in C include:
- 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.
- Identifiers cannot use keywords like int, while, etc. as identifiers.
- Identifiers must be unique.
Examples of valid C identifiers include "length," "total_sum," "size," "len," "num1," and "num_2". Examples of invalid C identifiers include "5size" (it begins with a digit), "@hello" (starts with a special character other than _), "int" (it is a keyword), "m n" (contains a blank space), and "m+n" (contains a + sign) .