C Variable Names (Identifiers)
C Variable Names (Identifiers) – Complete Guide
In C language, variable names are also called identifiers.
They are used to identify variables, functions, arrays, and other user-defined items in a program.
Choosing correct and meaningful identifiers is important for readability, correctness, and interviews.
1️⃣ What is an Identifier in C?
An identifier is the name given to a variable, function, array, or any other user-defined element.
Here:
-
age,totalMarks,grade→ identifiers
2️⃣ Rules for Naming Identifiers ⭐ (Very Important)
C identifiers must follow these rules:
✅ Allowed
-
Can contain letters (a–z, A–Z)
-
Can contain digits (0–9)
-
Can contain underscore
_ -
Must start with a letter or underscore
❌ Not Allowed
-
Cannot start with a digit
-
Cannot contain special symbols (
@,#,$,%, etc.) -
Cannot be a C keyword
-
Cannot contain spaces
3️⃣ Valid Identifier Examples ✅
✔ All follow C naming rules
4️⃣ Invalid Identifier Examples ❌
5️⃣ Case Sensitivity in C ⭐
C is case-sensitive.
✔ age and Age are different identifiers
6️⃣ Keywords Cannot Be Identifiers ❌
C keywords are reserved words.
Examples:
Some common C keywords:
7️⃣ Length of Identifiers ⚠️
-
C allows long identifiers
-
At least 31 characters are significant (compiler dependent)
✔ Valid, but keep names readable
8️⃣ Naming Conventions (Best Practices) ⭐
Although not mandatory, follow these good practices:
Use-meaningful names
Use-lowercase for variables
Use-uppercase for constants
Use-underscore for multi-word names
9️⃣ Identifiers for Different Elements
Variable
Function
Array
Structure
🔟 Identifier vs Variable Name ⭐
| Term | Meaning |
|---|---|
| Identifier | Name of any user-defined element |
| Variable Name | Identifier that stores a value |
📌 Every variable name is an identifier, but not every identifier is a variable
1️⃣1️⃣ Common Mistakes ❌
❌ Using keywords as names
❌ Starting with digits
❌ Using special symbols
❌ Writing unreadable names
❌ Confusing case sensitivity
📌 Interview Questions (Must Prepare)
-
What is an identifier in C?
-
Rules for naming identifiers
-
Can identifier start with
_? -
Is C case-sensitive?
-
Difference between keyword and identifier
-
Maximum length of identifier in C
✅ Summary
✔ Identifiers are names given to program elements
✔ Must start with letter or _
✔ Cannot use keywords or special symbols
✔ C is case-sensitive
✔ Good naming improves readability & maintenance
✔ Very important for basics, exams & interviews
