Keywords in C Programming

Keywords in C are the building blocks of the programming language. These reserved words have predefined meanings and functionalities that the C compiler recognizes. They cannot be used as identifiers, such as variable names or function names, ensuring clarity and consistency in programming.

This post covers all the keywords in C, their significance, and key differences from identifiers. Let’s dive deeper into understanding keywords in C with examples and details.


What Are Keywords in C?

Keywords in C are predefined words with a fixed meaning that the compiler understands. These reserved words cannot be modified or used for any other purpose, ensuring clarity and avoiding ambiguity in the code.

Key Features of Keywords

  1. Reserved Words:
    Keywords are predefined and reserved for specific tasks within the C language, ensuring consistent functionality.
  2. Case-Sensitive:
    All keywords in C are written in lowercase and are case-sensitive, distinguishing them from user-defined identifiers.
  3. Fixed Functionality:
    The meaning and purpose of keywords are fixed by the language and cannot be altered by the programmer.
  4. Integral to Syntax:
    Keywords form the foundational elements of C’s syntax, enabling control structures, data types, and program flow.
  5. Cannot Be Used as Identifiers:
    Keywords cannot be used as variable names, function names, or any user-defined labels to avoid conflicts in the program.
  6. Universal Across Compilers:
    Keywords behave uniformly across all C compilers, maintaining portability and consistency in C programs.

List of Keywords in C

A list of keywords in C or reserved words in the C programming language are mentioned below:

autobreakcasecharconstcontinuedefaultdo
doubleelseenumexternfloatforgotoif
intlongregisterreturnshortsignedsizeofstatic
structswitchtypedefunionunsignedvoidvolatilewhile

Specific Keywords With Descriptions

KeywordDescription
autoDeclares an automatic (local) variable.
breakExits a loop or a switch-case statement.
caseDefines individual cases in a switch block.
charDeclares a character data type.
constDeclares a constant variable.
continueSkips the current iteration of a loop.
defaultSpecifies the default case in a switch statement.
doStarts a do-while loop.
doubleDeclares a double precision floating-point variable.
elseSpecifies an alternative block in an if statement.
enumDefines an enumeration type.
externDeclares external variables or functions.
floatDeclares a floating-point variable.
forInitiates a for loop.
gotoTransfers control to a labeled statement.
ifIntroduces a conditional statement.
intDeclares an integer data type.
longDeclares a long integer data type.
registerDeclares a register variable for faster access.
returnExits from a function and optionally returns a value.
shortDeclares a short integer data type.
signedSpecifies a signed data type.
sizeofReturns the size of a data type or variable in bytes.
staticDeclares a static variable or function.
structDefines a structure type.
switchImplements a multi-way branching statement.
typedefDefines a new name for an existing type.
unionDeclares a union, which is a special data type.
unsignedDeclares an unsigned data type.
voidSpecifies no return type or an empty parameter list.
volatileIndicates that a variable can be changed unexpectedly.
whileStarts a while loop.

Key Properties of Keywords in C

  1. Predefined and Reserved:
    Keywords have fixed meanings defined by the C language and cannot be altered.
  2. Lowercase Only:
    All keywords in C are case-sensitive and must be written in lowercase.
  3. Recognized by Compiler:
    Keywords are processed uniquely by the compiler to perform specific tasks.
  4. Not Allowed as Identifiers:
    Keywords cannot be used as variable names, function names, or any other user-defined identifiers.
  5. Essential for Syntax:
    Keywords form the foundation of the C programming syntax, enabling control flow, data types, and other features.
  6. Universal Across Compilers:
    The meaning and functionality of keywords remain consistent across all C compilers.

Examples of Keywords in Use

Example 1: Control Flow Keywords

#include <stdio.h>  

int main() {  
    int num = 10;  

    // if-else keyword  
    if (num > 5) {  
        printf("Number is greater than 5\n");  
    } else {  
        printf("Number is 5 or less\n");  
    }  

    // for keyword  
    for (int i = 0; i < 5; i++) {  
        printf("Iteration %d\n", i);  
    }  

    return 0;  
}  
C

Example 2: Data Type Keywords

#include <stdio.h>  

int main() {  
    int integer = 100;          // int keyword  
    char character = 'A';       // char keyword  
    float floating = 10.5;      // float keyword  

    printf("Integer: %d\n", integer);  
    printf("Character: %c\n", character);  
    printf("Floating Point: %.2f\n", floating);  

    return 0;  
}  
C

Difference Between Keywords and Identifiers

AspectKeywordsIdentifiers
DefinitionReserved words with fixed meanings.User-defined names for variables, functions, etc.
ModificationCannot be modified or redefined.Can be defined by the programmer.
PurposePerforms specific functions.Identifies variables, functions, etc.
Case SensitivityAlways lowercase and case-sensitive.Case-sensitive but flexible in naming.
LengthPredefined, usually short.Can have any length within compiler limits.
CompilationRecognized and processed uniquely by the compiler.Processed as user-defined names.
Examplesint, while, if, return.myVariable, calculateSum.
Usage in CodeMandatory for specific tasks and syntax.Optional and used as needed by the programmer.

Youtube Links:

Keywords in C are the backbone of the programming language, providing the essential structure and functionality needed to write efficient programs. Mastering keywords is a crucial step in becoming proficient in C programming.

The next post is: Identifiers in C. Stay tuned to explore how identifiers are used in tandem with keywords to write meaningful and functional programs.

FAQs on Keywords in C

Q1. Why are keywords reserved in C?

Keywords are reserved to prevent ambiguity and ensure that their specific meaning and functionality remain consistent across all programs.

Q2. Can keywords be redefined?

No, keywords cannot be redefined in C as they have fixed functionality.

Q3. How many keywords are in C?

There are 32 keywords in C.

Q4. Are keywords case-sensitive?

Yes, keywords in C are case-sensitive. For example, int is valid, but Int is not a recognized keyword.