C Programming - Beginner to Brilliance / Basics of C Programming

Keywords & Identifiers

πŸ“Œ Why are they important?

Before you write any program in C, you need to name things (like variables, functions, etc.) and also use special reserved words (like int, return, while) to give instructions to the computer.

To do that, you must understand two concepts:

  • Keywords – special words that C already understands

  • Identifiers – the names you create

Let’s understand each one step by step.


πŸ”’ Keywords – The Reserved Words of C

Think of keywords like the grammar rules or vocabulary of the C language.

Just like in English you have:

  • if, but, while, and, etc.

In C, we have:

  • if, else, return, while, int, float, etc.

These are predefined in the language.

C already knows what these words mean β€” so you can’t redefine or reuse them.

❌ You can't do this:

int int = 10;             // ERROR: 'int' is a keyword, not allowed as a variable name

πŸ“‹ Complete List of 32 Keywords in C

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

πŸ”’ You can’t name a variable int or return β€” they are already reserved for the language.

Here they are, grouped for easier understanding:

πŸ—οΈ Data Types

  • int

  • float

  • char

  • long

  • double

  • void

  • short

πŸ” Control Flow

  • if

  • else

  • switch

  • case

  • default

  • continue

  • for

  • while

  • do

  • goto

  • break

  • return

🧰 Storage Class

  • auto

  • static

  • extern

  • register

🧩 Others

  • const

  • sizeof

  • struct

  • union

  • typedef

  • enum

  • signed

  • unsigned

  • volatile


πŸ“Œ Tip to Remember

πŸ“˜ "You can use a keyword, but you can’t name anything with it."

βœ… Allowed:

int a = 5;
if (a > 0) {
    return 0;
}

❌ Not allowed:

int return = 10;                           // return is a keyword

πŸ†” Identifiers – The Names You Create

An identifier is simply the name you give to:

  • Variables

  • Functions

  • Arrays

  • Structures

  • Any user-defined elements

🧠 Think of identifiers as labels you put on boxes in your room to remember what’s inside them.


πŸ“¦ Examples of Identifiers

int marks;         // 'marks' is an identifier
float weight;      // 'weight' is an identifier
void calculate();  // 'calculate' is an identifier

Each of these is a name created by you to hold or represent something in the program.


πŸ§‘β€πŸ« Rules for Naming Identifiers

C has strict rules about how you name things. Let’s break them down:

Rule

Explanation

βœ… Correct

❌ Wrong

Must begin with a letter (A-Z or a-z) or underscore (_) only

Can’t begin with a number

score, _score

1score, #score

Can contain letters, digits, and underscores only

No special characters or spaces

total_marks_1

total marks, total$

Case-sensitive

Total β‰  total

age, Age both allowed

β€”

Cannot be a keyword

Don’t name variables like int or return

myint, myreturn

int, while


πŸ” Examples (Valid Identifiers)

int age;
float total_marks;
char Grade;
int _counter;

❌ Examples (Invalid Identifiers)

int 1mark;     // starts with digit
int my-name;   // hyphen not allowed
int float;     // 'float' is a keyword

🧠 Best Practices for Identifiers

  • Use meaningful names: score is better than s

  • Use camelCase or snake_case:

    • totalMarks βœ…

    • total_marks βœ…

  • Avoid very short or confusing names like x1, abc, qwe


πŸ§ͺ Real-World Analogy

Imagine a kitchen:

  • Keywords are like fixed commands: "Turn on the stove", "Boil water". You can't change what they mean.

  • Identifiers are like names for your containers: "sugarContainer", "riceBowl". You can name them anything you like (as long as you follow the rules).