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.

  1. An identifier can include letters (a-z or A-Z), and digits (0-9).
  2. An identifier cannot include special characters except the ‘_’ underscore. 
  3. Spaces are not allowed while naming an identifier.
  4. An identifier can only begin with an underscore or letters.
  5. 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.
  6. The identifier must be unique in its namespace.
  7. C language is case-sensitive so, ‘name’ and ‘NAME’ are different identifiers.

The below image shows some valid and invalid identifiers in C language.

Valid and Invalid Identifiers in C

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.

Similar Reads

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....

Examples of Identifiers in C

In the below code, identifiers are named by following all the rules for valid identifiers. We use identifiers to name a structure, function, character data type, double data type, etc. If you are not aware of structures and functions in C then don’t worry you will learn them soon. The below code ran successfully without throwing any errors as we have followed all the rules....