Nearby lessons
16 of 124C - Identifiers
Identifiers are the names you give to variables, functions, arrays and structures in C. Learn the naming rules, which names are illegal, and the conventions professional C programmers follow.
What is an Identifier?
An identifier is simply a name that you invent. Every time you declare a variable, define a function, or create a structure, you are choosing an identifier.
Example01
The Five Rules
| # | Rule | Valid | Invalid |
|---|---|---|---|
| 1 | Letters, digits and underscore only | score_1 | score-1, my age |
| 2 | Must not begin with a digit | a1, _a1 | 1a |
| 3 | Cannot be a keyword | integer | int, for |
| 4 | No spaces or special symbols | totalMarks | total marks, total@ |
| 5 | Case-sensitive | sum ≠ Sum | — |
In simple words: letters, digits and underscores; never start with a digit; never use a keyword. That is the whole rule set.
Valid and Invalid Examples
Read each line and the reason beside it — this is the fastest way to internalise the rules:
Example03
Case Sensitivity in Action
C treats a change of case as a completely different name. This program declares three separate variables:
Example04
Identifiers vs Keywords vs Variables
These three words are often confused. The distinction is simple:
| Term | Who chooses the name | Example |
|---|---|---|
| Keyword | The C language — fixed, 32 of them | int, while, return |
| Identifier | You — any name that follows the rules | age, calculateTax |
| Variable | A storage location that has an identifier | int age; — age is the identifier |
Naming Conventions Professionals Use
The compiler accepts any legal name, but readable code follows conventions:
- Variables and functions —
camelCaseorsnake_case:totalMarks,total_marks. - Constants and macros —
UPPER_SNAKE_CASE:MAX_SIZE,PI. - Be descriptive —
studentCountbeatsscorx. - Loop counters — short names like
i,j,kare traditional and fine. - Avoid leading underscores — names like
_sizeand__xare reserved for the compiler and standard library.
Only the first 31 characters are guaranteed to be significant for internal names in C89. Two identifiers that differ only after character 31 may be treated as the same name by old compilers. Keep names well under that limit.
📝 Key Takeaways
- An identifier is a user-defined name for a variable, function, array or type.
- It may contain letters, digits and underscores only.
- It must not start with a digit.
- Keywords such as int and return cannot be identifiers.
- C is case-sensitive: age, Age and AGE are three different identifiers.
🧠 Test Your Knowledge
4 QuestionsProgress: 0 / 4