Understanding All 32 C Keywords: Meaning, Usage, and Examples A Journey Through C Keywords Learn C Keywords with Stories, Code, and Clarity

Inspector Chor and the Case of the Forbidden Names

🕵️‍♂️ Inspector Chor and the Case of the Forbidden Names

Why C keywords cannot be used as identifiers — friendly story, clear examples, and a printable cheat-sheet.
Read Cheat Sheet
By Champak RoySep 14, 2025

There was once an inspector named Chor. Yes, that was his actual name. He was honest, sharp, and known for catching real thieves. But one day, while chasing a suspect through Nai Basti, someone shouted:

“Chor ko pakdo!”

The crowd turned on him. He was tackled, cuffed, and dragged to the station—by his own constables. It took hours to clear the misunderstanding. But the lesson was clear: some names are too loaded to be used casually. In certain contexts, they carry fixed meanings. You can't just name your child "Fire" and expect calm when someone yells it in a crowded theatre.

And that, dear reader, is exactly why C keywords cannot be used as identifiers.

🔤 What Are Keywords in C?

In C, keywords are reserved words with predefined meanings. They form the grammar of the language and tell the compiler exactly what to do. You cannot use them to name variables, functions, or any other identifiers. Trying to name a variable return or if is like naming your dog “Break” and yelling it during a cricket match. Confusion is guaranteed.

// Invalid C example
int return = 5; // ❌ Error: 'return' is a keyword

📘 C Keywords with Serial Numbers, Explanations, and Code Samples

Below are all 32 reserved keywords in C, grouped by category. Each keyword includes a short explanation and two short code samples to illustrate its usage.

📦 Data Type Keywords (1–9)

1. int — Declares an integer variable.

int age = 25;
int sum = a + b;

2. char — Stores a single character.

char grade = 'A';
char initial = name[0];

3. float — Stores a decimal number (single precision).

float pi = 3.14;
float temperature = 36.6;

4. double — Stores a decimal number (double precision).

double distance = 123.456;
double result = sqrt(2.0);

5. short — Declares a smaller integer type.

short x = 100;
short y = -50;

6. long — Declares a larger integer type.

long population = 1000000;
long timestamp = time(NULL);

7. signed — Allows both positive and negative values.

signed int balance = -500;
signed char signal = -1;

8. unsigned — Allows only positive values.

unsigned int points = 250;
unsigned char byte = 255;

9. void — Indicates no return value or no data type.

void greet() { printf("Hello!"); }
void *ptr = malloc(10);
🔁 Control Flow Keywords (10–21)

10. if — Executes code if a condition is true.

if (x > 0) { printf("Positive"); }
if (flag == 1) start();

11. else — Executes code if the if condition is false.

if (x > 0) { ... } else { printf("Not positive"); }
if (valid) process(); else reject();

12. switch — Selects among multiple cases.

switch (choice) { case 1: printf("One"); break; }
switch (key) { case 'a': actionA(); break; }

13. case — Defines a branch in a switch block.

case 2: printf("Two");
case 'x': execute();

14. default — Specifies fallback behavior in a switch.

default: printf("Unknown");
default: handleFallback();

15. for — Loop with a counter.

for (int i = 0; i < 10; i++) { ... }
for (i = 0; i < n; i++) sum += arr[i];

16. while — Loop that runs while a condition is true.

while (x < 5) { x++; }
while (!done) wait();

17. do — Loop that runs at least once.

do { x--; } while (x > 0);
do { retry(); } while (error);

18. break — Exits a loop or switch block immediately.

for (int i = 0; i < 10; i++) {
  if (i == 5) break;
}
switch (option) {
  case 1: printf("Start"); break;
  case 2: printf("Stop"); break;
  default: printf("Invalid"); break;
}

19. continue — Skips the current iteration and moves to the next.

for (i = 0; i < 10; i++) {
  if (i % 2 == 0) continue;
  printf("%d ", i);
}
while (x < 100) {
  x++;
  if (x == 50) continue;
  process(x);
}

20. goto — Jumps to a labeled statement.

goto end;
...
end: printf("Done");
if (error) goto cleanup;
...
cleanup: free(ptr);

21. return — Exits a function and optionally returns a value.

return 0;
return sum;
🧠 Storage Class Keywords (22–25)

22. auto — Declares a local variable with automatic storage (default behavior).

auto int x = 10;
auto float rate = 2.5;

23. static — Preserves a variable’s value between function calls.

static int count = 0;
static char buffer[100];

24. extern — Refers to a variable or function defined in another file or scope.

extern int total;
extern void log();

25. register — Suggests storing a variable in a CPU register for faster access.

register int speed = 100;
register char ch = 'A';
🧩 User-Defined Type Keywords (26–29)

26. struct — Defines a group of variables under one name.

struct Point { int x, y; };
struct Point p1 = {10, 20};

27. union — Allows different data types to share the same memory location.

union Data { int i; float f; };
union Data d; d.i = 5;

28. enum — Declares a set of named integer constants.

enum Color { RED, GREEN, BLUE };
enum Color c = GREEN;

29. typedef — Creates a new name (alias) for an existing type.

typedef int Length;
Length l = 100;
🧪 Miscellaneous Keywords (30–32)

30. const — Declares a variable whose value cannot be changed.

const float pi = 3.14;
const int max = 100;

31. volatile — Tells the compiler that a variable may change unexpectedly.

volatile int flag;
volatile char *port = (volatile char *)0xFF00;

32. sizeof — Returns the size (in bytes) of a data type or variable.

int size = sizeof(int);
printf("%lu", sizeof(arr));

✅ Summary Table of All 32 C Keywords

No.KeywordCategory
1intData Type
2charData Type
3floatData Type
4doubleData Type
5shortData Type
6longData Type
7signedData Type
8unsignedData Type
9voidData Type
10ifControl Flow
11elseControl Flow
12switchControl Flow
13caseControl Flow
14defaultControl Flow
15forControl Flow
16whileControl Flow
17doControl Flow
18breakControl Flow
19continueControl Flow
20gotoControl Flow
21returnControl Flow
22autoStorage Class
23staticStorage Class
24externStorage Class
25registerStorage Class
26structUser-Defined Type
27unionUser-Defined Type
28enumUser-Defined Type
29typedefUser-Defined Type
30constMiscellaneous
31volatileMiscellaneous
32sizeofMiscellaneous

🔚 Final Summary

C is a language of precision, and its 32 keywords are the pillars of that precision. Each keyword carries a specific meaning and function—whether it's declaring a variable, controlling program flow, managing memory, or defining custom types. Just like Inspector Chor’s name caused confusion in the real world, using these reserved words as identifiers in code leads to errors and ambiguity.

Let your variables speak clearly. Let your logic flow smoothly. And let your code reflect the discipline and elegance that C was built upon.
Published with ❤️ by Champak Roy

Post a Comment

0 Comments

Me