C Programming
Keywords Reference
Essential Reference
C Keywords - Complete Reference Guide
Master all 32 C keywords with detailed explanations, usage examples, and programming best practices for effective C programming.
32 Keywords
Complete reference
Detailed Examples
Practical usage
Best Practices
Professional coding
Introduction to C Keywords
Keywords are reserved words in C that have special meaning to the compiler. These words cannot be used as identifiers (variable names, function names, etc.) because they are part of the language syntax.
Key Characteristics
- All keywords are in lowercase only
- C has 32 keywords (as per ANSI C standard)
- Keywords cannot be redefined or used as identifiers
- Each keyword serves a specific purpose
- Some keywords were added in later C standards (C99, C11)
Keyword Categories
- Data Type Keywords: Define variable types
- Control Flow Keywords: Control program execution
- Storage Class Keywords: Define scope and lifetime
- Other Keywords: Miscellaneous purposes
Important Note About Keywords
Keywords are case-sensitive in C. int is a keyword but INT, Int, or iNt are not keywords and can be used as identifiers (though not recommended).
Complete C Keywords Reference
Here is the complete list of all 32 C keywords with their categories, descriptions, and importance:
| Keyword | Category | Description & Importance | Common Usage |
|---|---|---|---|
| char | Data Type | Declares character type variables. Stores single characters (1 byte). Essential for text processing. | char grade = 'A'; |
| int | Data Type | Declares integer variables. Most commonly used data type for whole numbers. | int age = 25; |
| float | Data Type | Declares single-precision floating-point numbers (4 bytes). Used for decimal values. | float pi = 3.14; |
| double | Data Type | Declares double-precision floating-point numbers (8 bytes). Higher precision than float. | double e = 2.71828; |
| void | Data Type | Indicates no type or empty value. Used for functions that don't return values or pointers to any type. | void display(); |
| short | Data Type | Declares short integers (usually 2 bytes). Used when memory optimization is important. | short temp = -10; |
| long | Data Type | Declares long integers (4 or 8 bytes). Used for larger integer values. | long population = 7800000000L; |
| signed | Data Type | Indicates signed types (can be positive or negative). Default for char and int. | signed int value = -100; |
| unsigned | Data Type | Indicates unsigned types (only positive values). Doubles positive range. | unsigned int count = 100; |
| _Bool | Data Type | C99 addition for boolean type. Stores true (1) or false (0) values. | _Bool flag = 1; |
| _Complex | Data Type | C99 addition for complex numbers. Used in mathematical computations. | _Complex z; |
| _Imaginary | Data Type | C99 addition for imaginary numbers. Used in complex mathematics. | _Imaginary img; |
| if | Control Flow | Conditional statement. Executes code block if condition is true. Fundamental for decision making. | if (x > 0) { ... } |
| else | Control Flow | Alternative branch for if statement. Executes when if condition is false. | else { ... } |
| switch | Control Flow | Multi-way branch statement. Efficient alternative to multiple if-else statements. | switch (value) { ... } |
| case | Control Flow | Defines individual cases in switch statement. Must be constant expressions. | case 1: ... break; |
| default | Control Flow | Default case in switch statement. Executes when no case matches. | default: ... break; |
| for | Control Flow | Loop statement with initialization, condition, and increment. Most common loop. | for (int i=0; i<10; i++) |
| while | Control Flow | Loop that continues while condition is true. Checks condition before execution. | while (x > 0) { ... } |
| do | Control Flow | Loop that executes at least once. Condition checked after execution. | do { ... } while (x > 0); |
| break | Control Flow | Exits loops or switch statements immediately. Essential for loop control. | break; |
| continue | Control Flow | Skips current iteration and continues with next iteration of loop. | continue; |
| goto | Control Flow | Jumps to labeled statement. Generally avoided in modern programming. | goto error_handler; |
| return | Control Flow | Returns value from function and exits function. Required in non-void functions. | return 0; |
| auto | Storage Class | Default storage class for local variables. Rarely used explicitly. | auto int x = 10; |
| extern | Storage Class | Declares variable or function defined elsewhere. Used for global variables across files. | extern int globalVar; |
| static | Storage Class | Preserves variable value between function calls or limits visibility to file/function. | static int counter = 0; |
| register | Storage Class | Hints compiler to store variable in CPU register for faster access. Rarely used. | register int i; |
| const | Other | Declares read-only variables. Prevents modification, improves code safety. | const int MAX = 100; |
| sizeof | Other | Operator that returns size in bytes of variable or type. Essential for memory management. | sizeof(int) |
| typedef | Other | Creates alias names for existing types. Improves code readability. | typedef int Integer; |
| volatile | Other | Indicates variable may change unexpectedly. Used in embedded systems and multithreading. | volatile int sensor; |
| enum | Other | Defines enumeration types. Improves code readability with named constants. | enum Color {RED, GREEN, BLUE}; |
| struct | Other | Defines structure types. Groups related variables of different types. | struct Point {int x; int y;}; |
| union | Other | Defines union types. Shares memory between members. Used for memory efficiency. | union Data {int i; float f;}; |
Pro Tip: While memorizing all keywords is helpful, focus on understanding their usage patterns. The most commonly used keywords in everyday programming are:
int, if, else, for, while, return, void, and const.
Important Keywords Deep Dive
const vs #define
const:
- Creates read-only variables
- Has type checking
- Allocated memory
- Scope rules apply
#define:
- Text substitution by preprocessor
- No type checking
- No memory allocation
- File scope
const int MAX = 100;
#define MAX 100
Storage Classes Comparison
| Keyword | Scope | Lifetime |
|---|---|---|
auto |
Local | Function |
static |
Local/File | Program |
extern |
Global | Program |
register |
Local | Function |
break vs continue
break:
- Exits the loop immediately
- Used in switch and loops
- Transfers control after loop
continue:
- Skips current iteration
- Used only in loops
- Continues with next iteration
struct vs union
struct:
- Each member has own memory
- Size = sum of all members
- All members accessible
union:
- Members share memory
- Size = largest member
- Only one member at a time
Common Mistakes with Keywords
Common Error 1: Using keywords as identifiers
int int = 10; // ERROR: 'int' is a keyword
float return = 3.14; // ERROR: 'return' is a keyword
Common Error 2: Missing break in switch
switch (value) {
case 1: printf("One"); // Missing break
case 2: printf("Two"); break;
}
// If value=1, prints "OneTwo" (fall-through)
Common Error 3: Forgetting return in non-void function
int add(int a, int b) {
int sum = a + b;
// Missing return statement - undefined behavior
}
Best Practice: Always compile with warnings enabled (
-Wall -Wextra in GCC) to catch keyword-related errors early. Use an IDE with syntax highlighting to visually distinguish keywords from identifiers.
Key Takeaways
- C has 32 keywords that are reserved and cannot be used as identifiers
- Keywords are case-sensitive and must be written in lowercase
- Keywords are categorized into: Data Types, Control Flow, Storage Classes, and Other
- The most essential keywords for beginners are:
int,if,else,for,while,return constprovides type safety while#definedoes text substitutionstaticvariables preserve their value between function calls- Always include
breakin switch cases unless fall-through is intentional - Use
sizeof()to determine memory size of types/variables
Next Topics:
We'll cover input, output functions-print() and scanf() with examples.