Table of Contents
An identifier is a name used to identify program elements such as variables, functions, arrays, structures, and other declared entities. C places specific rules on how identifiers can be formed.
#include <stdio.h>
int main()
{
int student_count = 10;
int totalMarks = 500;
printf("Students: %d\n", student_count);
printf("Total marks: %d\n", totalMarks);
return 0;
}
Example Output #
Students: 10
Total marks: 500
Explanation #
The names:
student_count
totalMarks
are identifiers used to identify variables.
An identifier can contain:
- Letters (
A–Z,a–z) - Digits (
0–9) - Underscores (
_)
An identifier cannot begin with a digit.
Identifier Rules #
| Rule | Valid example | Invalid example |
|---|---|---|
| Can contain letters | count |
— |
| Can contain digits | value2 |
— |
Can contain _ |
total_value |
— |
| Cannot begin with a digit | value2 |
2value |
| Cannot contain spaces | student_count |
student count |
| Cannot contain operators | total_value |
total-value |
| Case-sensitive | count and Count |
— |
| Cannot be a keyword | number |
int |
C identifiers are case-sensitive:
int value;
int Value;
value and Value are two different identifiers.
Keywords reserved by the C language cannot be used as identifiers. The complete set of C keywords is covered in the next lesson.