Keywords and Identifiers in C
C Keywords
📌 Definition
Keywords are predefined and reserved words in C programming that have special meanings to the compiler.
-
Keywords are part of the language syntax
-
They cannot be used as identifiers (variable names, function names, etc.)
-
Since C is case-sensitive, all keywords must be written in lowercase
📌 Example
-
int→ keyword indicating the data type integer -
money→ variable name (identifier)
Here, int tells the compiler that money is an integer variable.
📌 Number of Keywords in ANSI C
ANSI C contains 32 keywords.
✔ List of ANSI C Keywords
Additional Keywords in C
Along with the 32 ANSI C keywords, C may support additional keywords depending on the compiler implementation.
C Identifiers
📌 Definition
An identifier is the name given to program elements such as:
-
Variables
-
Functions
-
Structures
-
Arrays
-
Objects
Identifiers must be unique so that each entity can be identified during program execution.
📌 Example
Here:
-
money→ identifier (variable name) -
accountBalance→ identifier -
int,double→ keywords (data types)
⚠ Identifier names must not be keywords.
Example: int cannot be used as an identifier.
Rules for Writing Identifiers
1️⃣ A valid identifier may contain:
-
Letters (A–Z, a–z)
-
Digits (0–9)
-
Underscore
_
2️⃣ The first character must be:
-
A letter, OR
-
An underscore
_
(Starting with _ is allowed but discouraged)
3️⃣ Length of identifier:
-
No strict limit in theory
-
Most compilers distinguish at least first 31 characters
4️⃣ Identifiers are case-sensitive
5️⃣ Keywords cannot be used as identifiers.
Valid Identifier Examples
Invalid Identifier Examples
| Identifier | Reason |
|---|---|
2csbmec | Cannot start with digit |
mec#cs2b | Illegal character # |
order-no | Illegal character - |
mec cs2b | Space not allowed |
Identifier Length Note
-
Identifiers can be very long
-
Some older implementations recognized only first 8 characters
-
Modern compilers typically recognize 31 or more
Example
Both are valid, but older compilers may treat them as identical because the first 8 characters are the same.
Therefore, avoid using such similar names in the same program.
Good Programming Practice
-
You may choose any valid identifier name (except keywords)
-
Always use meaningful and descriptive names
✔ Makes programs easier to:
-
Read
-
Understand
-
Maintain
-
Debug


Comments
Post a Comment