C Identifiers

Identifiers are user-defined tokens used to name variables, functions, etc. An identifier consists of a sequence of letters and digits. Underscore is also used. However, the first character of the identifier should a letter or an underscore.

So we can say that an identifier (i.e., variable names, function names, etc) is a collection of alphanumeric characters(begins with an alphabetical character or an underscore). Though there is logically no restriction on the length of the number of characters in an identifier, however for some compilers only 31 characters are significant to differentiate between 2 or more identifiers.

Rules for constructing C identifiers

  • The length of the identifiers should not be more than 31 characters.
  • Identifiers can be made up of letters and digits, and are case-sensitive.
  • The first character of an identifier must be a letter, which includes underscore (_).
  • The C language has 32 keywords which are reserved and may not be used as identifiers (eg, int,while, etc).
  • Commas or blank spaces cannot be specified within an identifier.

Example of valid identifiers

snippet
total, sum, average, _m _, sum_1, etc.

Example of invalid identifiers

snippet
2sum (starts with a numerical digit)
int (reserved word)
char (reserved word)
m+n (special character, i.e., '+')

Types of identifiers

  • Internal identifier
  • External identifier
Internal Identifier

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

External Identifier

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

Differences between Keyword and Identifier

KeywordIdentifier
keyword is a pre-defined word.The identifier is a user-defined word
It must be written in a lowercase letter.It can be written in both lowercase and uppercase letters.
Its meaning is pre-defined in the c compiler.Its meaning is not defined in the c compiler.
It is a combination of alphabetical characters.It is a combination of alphanumeric characters.
It does not contain the underscore character.It can contain the underscore character.

Below is an example.

snippet
int main()
{
    int a=10;
    int A=20;
    printf("Value of a is : %d",a);
    printf("\nValue of A is :%d",A);
    return 0;
}

Output

Output
Value of a is : 10 Value of A is :20

The above output shows that the values of both the variables, 'a' and 'A' are different.

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +