Identifier is one of the tokens which are used in C programming language. It is a name which is used to identify the variables, constants, functions, arrays, and also user-defined data.
We cannot use keywords as identifiers because keywords are reserved for special use. Once declared, we can use the identifier in later program statements which refers to the associated value.
The special kind of identifier is known as a statement label and it can be used in goto statements.
Rules
The rules for naming identifiers are as follows −
Identifier names are unique.
Cannot use a keyword as identifiers.
Identifier has to begin with a letter or underscore (_).
It should not contain white space.
Special characters are not allowed.
Identifiers can consist of only letters, digits, or underscore.
Only 31 characters are significant.
They are case sensitive.
Example
Following is the C program to identify which terms are called as identifiers −
/* C Program to Count Vowels and Consonants in a String */ #include <stdio.h> int main(){ char str[100]; int i, vowels, consonants; i = vowels = consonants = 0; printf("\nEnter any String : "); gets(str); while (str[i] != '\0'){ if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U'){ vowels++; } else consonants++; i++; } printf("\n no of Vowels in the given String = %d", vowels); printf("\n no of Consonants in the given String = %d", consonants); return 0; }
Output
When the above program is executed, it produces the following result −
Enter any String : Tutorials Point no of Vowels in the given String = 6 no of Consonants in the given String = 9
In the above program the identifiers are −
Str, i, vowels, consonants