Nearby lessons

16 of 124

C - 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
CCode Cell
1#include <stdio.h>
2 
3int total; // total - identifier for a variable
4float averageMarks; // averageMarks - identifier
5 
6int addNumbers(int a, int b) // addNumbers, a, b - all identifiers
7{
8 return a + b;
9}
10 
11int main() // main - a special identifier
12{
13 total = addNumbers(10, 20);
14 printf("Total: %d\n", total);
15 return 0;
16}
Output
Total: 30

The Five Rules

#RuleValidInvalid
1Letters, digits and underscore onlyscore_1score-1, my age
2Must not begin with a digita1, _a11a
3Cannot be a keywordintegerint, for
4No spaces or special symbolstotalMarkstotal marks, total@
5Case-sensitivesumSum
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
CCode Cell
1/* VALID identifiers */
2int age;
3int _count; // underscore start is allowed
4int total2; // digit is fine, just not first
5int studentName; // camelCase
6int max_value; // snake_case
7int PI_LIMIT; // uppercase is allowed
8 
9/* INVALID identifiers - each is a compiler error */
10// int 2age; // starts with a digit
11// int my age; // contains a space
12// int total-marks; // hyphen is the minus operator
13// int float; // 'float' is a keyword
14// int rate%; // % is not allowed
Output
(the commented lines would each fail to compile)

Case Sensitivity in Action

C treats a change of case as a completely different name. This program declares three separate variables:

Example04
CCode Cell
1#include <stdio.h>
2 
3int main()
4{
5 int marks = 50;
6 int Marks = 70;
7 int MARKS = 90;
8 
9 printf("marks = %d\n", marks);
10 printf("Marks = %d\n", Marks);
11 printf("MARKS = %d\n", MARKS);
12 return 0;
13}
Output
marks = 50
Marks = 70
MARKS = 90

Identifiers vs Keywords vs Variables

These three words are often confused. The distinction is simple:

TermWho chooses the nameExample
KeywordThe C language — fixed, 32 of themint, while, return
IdentifierYou — any name that follows the rulesage, calculateTax
VariableA storage location that has an identifierint age;age is the identifier

Naming Conventions Professionals Use

The compiler accepts any legal name, but readable code follows conventions:

  • Variables and functionscamelCase or snake_case: totalMarks, total_marks.
  • Constants and macrosUPPER_SNAKE_CASE: MAX_SIZE, PI.
  • Be descriptivestudentCount beats sc or x.
  • Loop counters — short names like i, j, k are traditional and fine.
  • Avoid leading underscores — names like _size and __x are 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 Questions
Progress: 0 / 4