Rules to Name an Identifier in C
A programmer has to follow certain rules while naming variables. For the valid identifier, we must follow the given below set of rules.
- An identifier can include letters (a-z or A-Z), and digits (0-9).
- An identifier cannot include special characters except the ‘_’ underscore.
- Spaces are not allowed while naming an identifier.
- An identifier can only begin with an underscore or letters.
- We cannot name identifiers the same as keywords because they are reserved words to perform a specific task. For example, printf, scanf, int, char, struct, etc. If we use a keyword’s name as an identifier the compiler will throw an error.
- The identifier must be unique in its namespace.
- C language is case-sensitive so, ‘name’ and ‘NAME’ are different identifiers.
The below image shows some valid and invalid identifiers in C language.
C Identifiers
In C programming language, identifiers are the building blocks of a program. Identifiers are unique names that are assigned to variables, structs, functions, and other entities. They are used to uniquely identify the entity within the program. In the below example “section” is an identifier assigned to the string type value.
char section = 'A';
For the naming of identifiers, we have a set of rules in C to be followed for valid identifier names.