Explain the rules for forming identifier names. Give examples of valid and invalid identifiers names for the same.

2.B) Explain the various rules for forming identifier names. Give examples of valid and
invalid identifiers names for the same.

Answer:-

Rules for forming identifier names:-

  1. Identifier should contain only alphabets (A-Z), (a-z), numerals(0-9) and underscore (_)
  2. The identifier should start with alphabet or underscore, but not a numeric character
  3. The first 31 characters in an identifier are significant, the rest of characters are neglected
  4. No reserve words (keywords) of C language can be used as identifiers
  5. Identifiers are case sensitive

Examples of valid identifiers:-
food, counter_7, max_1, min_1


Examples of Invalid identifiers:-
$num //$ is special character
int //keyword
name 1 //space not allowed

Leave a Reply

Your email address will not be published. Required fields are marked *