Keywords & Identifiers in C

A C program is made up of many words, but not all words behave the same. Some words have special meaning (keywords) and some words are names created by the programmer (identifiers). Understanding the difference is essential for writing correct C programs.

What Are Keywords?

Keywords are reserved words in C that have a fixed meaning defined by the language. You cannot change their meaning, and you cannot use them as identifiers (variable or function names).

There are 32 keywords in C.

List of C Keywords

auto      double    int       struct  
break     else      long      switch  
case      enum      register  typedef  
char      extern    return    union  
const     float     short     unsigned  
continue  for       signed    void  
default   goto      sizeof    volatile  
do        if        static    while  

These words are strictly reserved and recognized by the compiler.

Examples of Keywords

int age;
float salary;
return 0;

What Are Identifiers?

Identifiers are names given by the programmer to variables, functions, arrays, structures, etc.

Examples:

int marks;
float totalScore;
void calculate();

Here, marks, totalScore, and calculate are identifiers.

Rules for Identifiers

To create valid identifiers, you must follow certain rules:

✔ Valid: sum, total_marks, _data, player1 ✖ Invalid: 1value, total value, float (keyword)

Examples of Identifiers (Valid & Invalid)

// Valid
int number;
float total_sum;

// Invalid
int 45count;     // starts with digit
float double;     // using a keyword
char first name;  // contains space

Difference Between Keywords and Identifiers

Keywords:
- Predefined by C
- Cannot be changed
- Cannot be used as names

Identifiers:
- Created by the programmer
- Names for variables/functions
- Must follow naming rules

Diagram: Keywords vs Identifiers

           ┌──────────────┐
           │    TOKENS    │
           └──────┬───────┘
                  │
     ┌────────────┴──────────────┐
     │                           │
 ┌───────────┐             ┌──────────────┐
 │ Keywords  │             │ Identifiers  │
 └───────────┘             └──────────────┘
     Fixed                      User-defined
     Meaning                    Names

Practice Questions

  1. What are keywords? List any 10.
  2. What are identifiers? Give 5 examples.
  3. Write any five rules for naming identifiers.
  4. Why can't we use keywords as identifiers?
  5. Identify keywords and identifiers in a given C program.

Practice Task

Write a C program and list all the identifiers you used. Also explain why each identifier name was chosen.