WHAT ARE IDENTIFIERS IN C?

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.


RULES FOR NAMING IDENTIFIERS IN C

  • We can not use any keyword as an identifier.
  • All the identifiers should have a unique name in the same scope.
  • Identifiers can not start with a digit.
  • The first character of an identifier should always start with an alphabet or underscore, and then it can be followed by any of the characters, digit, or underscore.
  • The special characters such as '*','#','@','$' are not allowed within an identifier.
  • All the identifiers are case sensitive means the identifiers "hello" and "Hello" will be treated differently. However, both names are identical, but one has a lowercase alphabet, and the other has an uppercase alphabet.
  • Length of an identifier should not exceed 31 characters.
  • Any blank spaces or commas are not allowed within an identifier.

EXAMPLES OF VALID IDENTIFIERS IN C

  • length - It contains only lowercase alphabets.
  • total_sum - It contains only '_' as a special character.
  • _size - It starts with an underscore '_'.
  •  len_ - Contains lowercase alphabets and an underscore.
  • num1 - Here, the numeric digit comes at the end.
  • num_2 - It starts with lowercase and ends with a digit.


EXAMPLES OF INVALID IDENTIFIERS IN C

  • 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)
  • m+n (contains a special character)