- What are Keywords in C and why they're reserved
- What are Identifiers and how to name them properly
- What are Variables and how to use them
- Simple rules for naming variables
- Different ways to declare variables
1. What are Keywords in C?
Think of keywords as the "VIP words" of C programming. They're reserved exclusively for the language itself. You can't use them for anything else — not for variable names, function names, or any other identifiers. It's like trying to use a police siren for your bicycle. It just won't work!
C comes with exactly 32 keywords. Some of the most common ones you'll see every day are:
int, char, float, double, if, else,
for, while, switch, return, break, and continue.
2. What are Identifiers in C?
Identifiers are simply the names you make up for things in your program — variables, functions, arrays, structures, and unions. Think of it like naming your pet. You get to choose, but there are some ground rules.
An identifier can have letters, digits, and underscores. But here's the catch — it must start with a letter or an underscore (_).
And remember, you can't use a keyword as an identifier. That's like naming your dog "Dog." It doesn't work.
Rules for Naming Identifiers:
- Start with a letter (A-Z or a-z) or underscore (
_) - After that, you can use letters, digits, or underscores
- Don't use reserved keywords — they're off-limits
- Case matters —
myVarandmyvarare completely different - No special characters like
@,#,$— they're not allowed - Choose names that actually make sense. Future you will thank you.
3. What are Variables in C?
A variable is basically a labeled storage box in your computer's memory. You can put data in it, change it whenever you want, and use it again and again. Simple, right?
Here's a quick example to make it crystal clear:
int age = 25;
float salary = 45000.50;
char grade = 'A';
Let's use a real-world scenario. Imagine you're calculating the area of a triangle. You need the height and base. Those values need a temporary home in memory — that's exactly what variables do. Each variable is just a named spot in your computer's memory where you can store values.
4. Rules to Declare Variables in C
Before using a variable, you need to declare it. That just means telling the compiler two things: what type of data it will hold, and what name you're giving it. It's like reserving a parking spot before you park your car.
- No two variables can have the same name in the same scope — it's like having two people with the same ID card.
- Variable names can start with a letter or underscore, but never a number.
- Don't use reserved keywords as variable names — they're already spoken for.
- Only letters, numbers, and underscores are allowed in variable names. Keep it clean.
- Every declaration must end with a semicolon (
;) — the compiler expects it. - If multiple variables have the same data type, you can declare them in a single line.
- Always choose meaningful names. It makes your code readable and maintainable.
5. Types of Variable Declarations
i. Primary Type Declaration
This is the standard way to declare variables using built-in data types like int,
float, char, double, and so on.
Declaring a single variable:
char grade = 'A';
Declaring multiple variables in one line:
int length = 12, width = 13, depth = 14;
ii. User-Defined Type Declaration
In C, you're not just stuck with the built-in types. You can create your own custom data types using the built-in ones. This gives you incredible flexibility.
1. Structure (struct): Groups different types of data into one unified type.
struct Student {
int rollNo;
char name[50];
float marks;
};
2. Union (union): Similar to structure, but all members share the same memory location.
union Data {
int i;
float f;
char str[20];
};
3. Typedef (typedef): Gives a new, more intuitive name to an existing data type.
typedef unsigned int unit;
Quick Comparison: Keywords vs Identifiers vs Variables
| Feature | Keywords | Identifiers | Variables |
|---|---|---|---|
| What it is | Reserved words with fixed meaning | Names you give to program elements | Named memory locations holding data |
| Created by | The language itself | You (the programmer) | You (the programmer) |
| Can you use it as a variable name? | No | Yes | Yes |
| Examples | int, char, if |
myVar, _count |
int age = 25; |
Frequently Asked Questions About Variables and Identifiers in C
1. Can I name a variable after a keyword?
No. Keywords are reserved by the language. You can't name your variable int, char, or if — the compiler will simply reject it.
2. Can a variable name start with a digit?
No. Variable names must start with a letter or underscore. 1var is invalid, but var1 works perfectly.
3. Is C case-sensitive?
Yes. C treats uppercase and lowercase letters as completely different. So myVar and myvar are two separate variables.
4. What's the difference between a variable and an identifier?
An identifier is any name you give to something in your program — variables, functions, arrays, etc. A variable is a specific type of identifier that actually holds data in memory.
5. Why should I care about meaningful names?
Good names make your code easier to read, understand, and maintain. int studentAge = 18; is instantly understandable. int a = 18;? Not so much. Your future self will appreciate clear, descriptive names.
💡 Quick tip: Always use clear, descriptive names for your variables. It's a small habit that pays off big time.
🧠 Quick Quiz: Test Your Knowledge
Q1: Which of these is a valid variable name in C?
- A)
1stNumber - B)
_count - C)
int - D)
my-var
Show Answer
Answer: B) _count
Variable names must start with a letter or underscore. 1stNumber starts with a number, int is a keyword, and my-var contains a hyphen (not allowed).
Q2: How many keywords does C language have?
- A) 20
- B) 32
- C) 45
- D) 50
Show Answer
Answer: B) 32
The C language has exactly 32 reserved keywords.
Q3: What is the difference between a variable and an identifier?
- A) They are the same thing
- B) Identifiers are reserved words
- C) A variable is a specific type of identifier that holds data
- D) Variables can only store numbers
Show Answer
Answer: C) A variable is a specific type of identifier that holds data
An identifier is any name you give to program elements. A variable is specifically an identifier that stores data in memory.
🎯 Key Takeaway: Understanding variables, identifiers, and keywords is the first step toward mastering C programming. Once you get these basics right, everything else becomes much easier.