C Variable Names (Identifiers)
1. What is an Identifier?
-
An identifier is a name given to variables, functions, arrays, or any user-defined item in C.
-
It is used to identify and refer to memory locations where data is stored.
Example:
2. Rules for Naming Variables (Identifiers)
-
Start with a letter or underscore (_):
-
Can contain letters, digits, and underscores:
-
Cannot be a C keyword (reserved word):
-
Case-sensitive:
-
No special characters or spaces allowed:
3. Best Practices for Variable Names
-
Use meaningful names:
-
Use camelCase or snake_case for multi-word names:
-
Avoid single letters unless in loops:
-
Keep names short but readable.
4. Examples of Valid Identifiers
5. Examples of Invalid Identifiers
6. Example Program Using Identifiers
Output:
✅ Key Takeaways:
-
Always follow the rules for identifiers.
-
Use meaningful names for clarity.
-
C is case-sensitive, so be consistent.
