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

  1. We can not use any keyword as an identifier.
  2. All the identifiers should have a unique name in the same scope.
  3. Identifiers can not start with a digit.
  4. 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.
  5. The special characters such as '*','#','@','$' are not allowed within an identifier.
  6. 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.
  7. Length of an identifier should not exceed 31 characters.
  8. 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)

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.