1.18 Identifiers in c

 Identifiers: -

  • Identifiers are names used for program elements like variables, functions, arrays, structures, unions, constants, and labels.
  • Every identifier must have a unique name to help to recognize and use values or functions during program execution.
  • The value of an identifier can change during the program as per the programmer's need.
  • Identifiers can have uppercase letters, lowercase letters, digits, and underscores.
  • It uses 63 characters (26 uppercase, 26 lowercase + 10 digits) can be used to form identifiers. Here underscore character is treated as letter, commonly used in the middle of identifiers.

 

Rules for Writing Identifiers: -

  • An identifier must start with a letter (A–Z or a–z) or an underscore _.
  • It can contain letters, digits (0–9), or underscores after the first character.
  • An identifier cannot begin with a digit.
  • Uppercase and lowercase letters are different (identifiers are case-sensitive).
  • Do not use spaces or commas in identifiers.
  • Do not use C keywords (like int, main, return) as identifiers.
  • Try to keep identifiers shorter than 31 characters.
  • Use simple, meaningful names that are easy to type and read.

 

Valid identifiers            :         

total                

sum                    

average

_total 

sum_ 

mark_1 

x1

 

Invalid identifiers :

1x           -              begins with a digit 

char -           reserved word 

x+y        -             special character


 Note: Underscore character is usually used as a link between two words in long identifiers.

 

Difference between Keywords words and identifiers

 

Keyword

Identifier

Predefined-word.

User-defined word.

Must be written in lowercase only.

Can write in lowercase and uppercase.

Has fixed meaning.

Must be meaningful in the program.

Whose meaning has already been explained to the C compiler.

Whose meaning not explained to the C compiler.

Combination of alphabetic characters.

Combination of alphanumeric characters.

Used only for it intended purpose.

Used for required purpose.

Underscore character is not considered as a letter.

Underscore character is considered as a letter.

Popular posts from this blog

1.19 Operators in c programming

2.4 Arrays in c programming

2.1 Control statements in C programming (sequential & conditional)