Keywords, Identifiers & Variables in C
Keywords, Identifiers & Variables in C
Introduction
When you start learning programming, you will often come across terms like keywords, identifiers, and variables. These are the basic building blocks of any C program.
Understanding these concepts clearly will help you write programs correctly and avoid common mistakes.
What are Keywords in C?
Keywords are reserved words in C that have a predefined meaning.
You cannot use them as names for variables or functions.
👉 They are part of the C language itself.
Examples of Keywords
-
int -
float -
if -
else -
return -
while
👉 These words are already defined by the compiler.
⚠️ Important Rule
❌ You cannot use keywords as variable names
Example:
int int = 10; // ❌ Invalid
What are Identifiers?
Identifiers are the names given to variables, functions, arrays, etc.
👉 They help us identify different elements in a program.
Examples of Identifiers
int age;
float salary;
int totalMarks;
Here:
-
age,salary,totalMarks→ identifiers
Rules for Identifiers
-
✔ Must start with a letter or underscore
_ - ✔ Can contain letters, digits, underscore
- ✔ Cannot start with a number
- ✔ Cannot be a keyword
-
✔ Case-sensitive (
age≠Age)
What are Variables?
A variable is a named memory location used to store data.
👉 It allows us to store and manipulate values in a program.
Syntax of Variable Declaration
data_type variable_name;
Examples
int age = 20;
float price = 99.5;
char grade = 'A';
Example Program
#include <stdio.h>
int main() {
int age = 18;
float height = 5.9;
char grade = 'A';
printf("Age = %d\n", age);
printf("Height = %f\n", height);
printf("Grade = %c\n", grade);
return 0;
}
Output
Age = 18
Height = 5.900000
Grade = A
Explanation of the Program
-
int,float,char→ Keywords (data types) -
age,height,grade→ Identifiers - Values assigned → Variables storing data
Difference Between Keywords, Identifiers & Variables
| Feature | Keywords | Identifiers | Variables |
|---|---|---|---|
| Meaning | Reserved words | Names of elements | Storage locations |
| Defined by | Language | Programmer | Programmer |
| Example | int, if |
age, total |
int age = 20; |
Common Mistakes
- ❌ Using keywords as identifiers
- ❌ Starting identifier with number
- ❌ Forgetting data type
- ❌ Case mismatch
Pro Tips
-
✔ Use meaningful variable names (
totalMarksinstead oft) - ✔ Follow naming conventions
- ✔ Keep names simple and clear
- ✔ Practice writing small programs
Conclusion
Keywords, identifiers, and variables are the foundation of C programming. Once you understand these clearly, writing programs becomes much easier and more structured.
👉 This article is part of Dharani Tech Edu Hub — where learning programming is made simple and practical.
Comments
Post a Comment