C Identifiers

C Identifiers


C identifiers represent names in C programs, for example, variables, functions, structures, arrays, unions, labels, etc. An identifier may be composed of letters such as uppercase, lowercase letters, underscores, numerals, but the initial letter is either an alphabet or an underscore. If an identifier is not used in an external linkage, it is called an internal identifier. If an identifier is used in an external linkage, it is called an external identifier.

We can say that an identifier is a collection of alphanumeric characters that starts with either an alphabetic character or an underscore, which is used to represent various programming elements such as variables, functions, structures, arrays, unions, labels, etc. There are alphabet characters (uppercase & lowercase), underscore characters, and ten numeric digits (0–9) that represent identifiers. There are a total of 63 alphanumeric characters that represent identifiers.

C Identifiers

Rules for creation of C identifier

  • The first character of an identifier must be either an alphabet or an underscore, and can be followed by any character, digit, or underscore.
  • It should not start with any numeric digits.
  • In identifiers, both uppercase and lowercase letters are different. Therefore, we can say that the identifiers are sensitive.
  • Comm or spaces within an identifier cannot be specified.
  • Keywords cannot be represented as an identifier.
  • The length of identifiers should not exceed 31 characters.
  • Identifiers should be written in such a way that it is meaningful, short and easy to read.
Exmple of valid identifiers

average, fine2, boost, _moon, sum_1, etc.

Invalid identifier example

2continue (starts with a numeric digit)
void (reserved word)
Char (reserved word)
m + n (special characters, ie, ‘+’)

Types of C identifiers

  • Internal identifier
  • External identifier
Internal identifier

If an identifier is not used in an external linkage, it is known as an internal identifier. Internal identifiers can be local variables.

External identifier

If an identifier is used in an external linkage, it is known as an external identifier. External identifiers can be function names, global variables.

Difference between keyword and identifier

S. no.Keywordidentifier
1The keyword is a pre-defined term.
Identifier is a user-defined term
2It has to be written in lowercase letter.It can be written in both lowercase as well as uppercase.
3Its meaning is pre-defined in the C compiler.Its meaning is not defined in the C compiler.
4This alphabet is a combination of characters.It is a combination of alphanumeric characters.
5It does not include the underscore character.It may contain an underscore character.
Let us understand through an example.
int main()
{
int x=10;
int X=20;
printf("Value of x is : %d",x);
printf("nValue of X is :%d",X);
return 0;
}

The above output shows that the values ​​of both the variables ‘x’ and ‘X’ are different. Therefore, we conclude that the identifiers are case sensitive.

character set

A character set is a collection of letters, digits, white spaces and some special characters that are valid in the C language.

The letter

Uppercase: A B C …………………………….. X Y Z
Lowercase: a b c ………………………………… x y z
C accepts both lowercase & uppercase alphabets as variables and functions.

Digits

0 1 2 3 4 5 6 7 8 9

Special Characters

Special Characters in C Programming

, < > . _
( ) ; $ :
% [ ] # ?
‘ & { } “
^ ! * / |~ +

White space Characters

Blanks, newlines, horizontal tabs, vertical tabs, carriage, return and form feeds.

Leave a Comment