In C programming, writing readable and understandable code depends greatly on how we name elements like variables, functions, arrays, and structures. This naming is done using identifiers. On the other hand, keywords are reserved words that form the core syntax of the C language.
Understanding the difference between the two is essential for writing valid and error-free code.
1. Identifiers in C
Identifiers are names given to various programming elements, such as:
- Variables
- Functions
- Arrays
- Structures
- Constants
- Labels
Identifiers help the compiler and the programmer differentiate between different entities in a C program.
Rules for Forming Identifiers
C has strict rules for defining valid identifiers:
✔ Allowed
- Alphabets (A–Z, a–z)
- Digits (0–9)
- Underscore
_
❌ Not Allowed
- Spaces
- Special symbols (@, #, %, $, &)
- Keywords
- Starting with digits
Naming Rules Explained
1. Identifiers must begin with a letter or underscore
int value; // Valid
int _temp; // Valid
int 2data; // Invalid
2. Case-sensitive
Count and count are considered two different identifiers.
3. No length limit (but recommended to keep short and meaningful)
4. Keywords cannot be used as identifiers
int int; // Invalid
Examples of Valid Identifiers
total
sum_2025
myVariable
marks_list
_student
Examples of Invalid Identifiers
student name // Space not allowed
2total // Starts with digit
float*value // Contains special symbol
return // Keyword
Choosing Good Identifier Names
Good code practices recommend:
- Use meaningful names
- Avoid overly short or overly long names
- Follow naming patterns (camelCase or snake_case)
Good:
int totalMarks;
float product_price;
Bad:
int t;
float x1pqr;
2. Keywords in C
Keywords are predefined and reserved words in the C language.
They have a fixed meaning and cannot be used as identifiers.
C has 32 standard keywords.
List of C Keywords
Data Types
int float char double void
Control Statements
if else switch case default
for while do break continue
goto return
Storage Class Specifiers
auto static extern register
Type Modifiers
short long signed unsigned
Other Keywords
const sizeof typedef struct union enum
volatile
Examples Using Keywords
1. Using data type keywords
int age = 22;
float salary = 35000.50;
2. Using control statements
if (age > 18) {
printf("Eligible");
} else {
printf("Not Eligible");
}
3. Using storage class
static int count = 0;
4. Using type modifiers
unsigned int voters = 45000;
Keywords vs Identifiers (Comparison Table)
| Feature | Identifier | Keyword |
|---|---|---|
| Meaning | Name given to entities | Reserved words |
| Defined by | Programmer | C language |
| Customizable | Yes | No |
| Case-sensitive | Yes | Yes |
| Can be used as variable names | Yes | No |
| Examples | total, sum_1, _mark | int, if, return |
3. Summary
- Identifiers: User-defined names for variables, functions, arrays, etc.
- Keywords: Predefined reserved words with special meaning in C.
- Identifiers cannot use keywords or special symbols.
- C has 32 total keywords.
Understanding identifiers and keywords is essential before you start writing programs in C.
🔗 View other articles about C Programming:
https://savanka.com/category/learn/c-programming