Dr. Roger Ianjamasimanana

Reserved keywords in C and their importance

By Dr. Roger Ianjamasimanana

1. What are reserved keywords?

Reserved keywords are predefined, fixed words in the C language that have special meanings and purposes. They cannot be used as identifiers (names of variables, functions, etc.) in your programs. This guide introduces you to the various reserved keywords in C, their categories, and their significance in programming.

2. Introduction to reserved keywords in C

Reserved keywords define the syntax and structure of C programs and control the behavior of various operations. Familiarity with these keywords is essential to write error-free C programming.

3. List of reserved keywords in C

Below is a comprehensive table listing all the reserved keywords in the C programming language. I also list their specific purpose in the functionality of C programs.

List of reserved keywords in C and their functionalities
Keywords Descriptions Categories
auto Specifies automatic storage duration. Storage class
break Exits from a loop or switch statement. Control statement
case Defines a case in a switch statement. Control statement
char Defines a character data type. Data type
const Specifies that a variable's value cannot be changed. Type qualifier
continue Skips the current iteration of a loop. Control statement
default Specifies the default case in a switch statement. Control statement
do Begins a do-while loop. Control statement
double Defines a double-precision floating-point data type. Data type
else Specifies an alternative branch in an if statement. Control statement
enum Defines an enumeration type. Data type
extern Specifies external linkage for variables or functions. Storage class
float Defines a single-precision floating-point data type. Data type
for Begins a for loop. Control statement
goto Transfers control to a labeled statement. Control statement
if Begins a conditional statement. Control statement
inline Suggests that a function should be inlined. Storage class
int Defines an integer data type. Data type
long Defines a long integer data type. Data type
register Suggests that a variable should be stored in a register. Storage Class
restrict Specifies that a pointer is the only reference to the object it points to. Type qualifier
return Exits a function and optionally returns a value. Control Statement
short Defines a short integer data type. Data type
signed Specifies that a variable can hold both positive and negative values. Type qualifier
sizeof Returns the size of a data type or variable. Operator
static Specifies static storage duration or internal linkage. Storage Class
struct Defines a structure type. Data type
switch Begins a switch statement. Control Statement
typedef Creates an alias for a Data type. Type Definition
union Defines a union type. Data type
unsigned Specifies that a variable can only hold positive values. Type qualifier
void Specifies that a function does not return a value or that a pointer does not have a type. Data type
volatile Indicates that a variable may be changed externally and prevents the compiler from optimizing it. Type qualifier
while Begins a while loop. Control statement

4. Categories of reserved keywords

Reserved keywords in C can be categorized based on their functionality and usage within the language. Understanding these categories helps in grasping how different parts of the language interact and function together.

4.1 Data types

Data type keywords define the type of data that can be stored in variables. They determine the size and layout of the variable's memory.

int main() {
    int number;      // Integer
    float decimal;   // Floating-point number
    char letter;     // Character
    double large_ecimal; // Double-precision floating-point number
    return 0;
}
    

4.2 Storage classes

Storage class keywords define the scope, visibility, and lifetime of variables and/or functions.

void example() {
    static int counter = 0; // Retains value between function calls
    counter++;
}
    

4.3 Type qualifiers

Type qualifiers add additional information about how a variable can be used.

const int immutable = 10; // Cannot be modified after initialization
volatile int external_change; // May be changed outside the program's control
    

4.4 Control statements

Control statement keywords control the flow of execution in a program.

#include <stdio.h>
for(int i = 0; i < 10; i++) {
    if(i % 2 == 0) {
        continue; // Skip even numbers
    }
    printf("%d\n", i);
}
    

5. Importance of reserved keywords

Reserved keywords ensures that the compiler understands the intent of the programmer, facilitating accurate translation of code into executable instructions. Misusing reserved keywords, such as attempting to use them as identifiers, can lead to syntax errors and undefined behavior. Therefore, a thorough understanding of them is essential for effective C programming.

6. Conclusion

Mastering reserved keywords in C is a pivotal step towards becoming a proficient C programmer. These keywords form the backbone of the language, enabling the creation of robust and efficient programs. By understanding their categories, functionalities, and proper usage, programmers can harness the full potential of C, writing clear, maintainable, and error-free code.

feature-top
Readers’ comment
feature-top
Log in to add a comment