- C Programming Tutorial
- C - Home
- Basics of C
- C - Overview
- C - Features
- C - History
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Type Casting
- C - Booleans
- Constants and Literals in C
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Unary Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Misc Operators
- Decision Making in C
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- Loops in C
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- Functions in C
- C - Functions
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Pointer to an Array
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Initialization of Pointer Arrays
- C - Pointers vs. Multi-dimensional Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Special Characters
- C Structures and Unions
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Lookup Tables
- C - Dot (.) Operator
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- File Handling in C
- C - Input & Output
- C - File I/O (File Handling)
- C Preprocessors
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- C - Macros
- C - Header Files
- Memory Management in C
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Cheat Sheet
- C - Useful Resources
- C - Discussion
C - Keywords
Keywords are those predefined words that have special meaning in the compiler and they cannot be used for any other purpose. As per the C99 standard, C language has 32 keywords. Keywords cannot be used as identifiers.
The following table has the list of all keywords (reserved words) available in the C language:
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
continue | for | signed | void |
do | if | static | while |
default | goto | sizeof | volatile |
const | float | short | unsigned |
All the keywords in C have lowercase alphabets, although the keywords that have been newly added in C, do have uppercase alphabets in them. C is a case-sensitive language. Hence, int is a keyword but INT, or Int are not recognized as a keyword. The new keywords introduced from C99 onwards start with an underscore character. The compiler checks the source code for the correctness of the syntax of all the keywords and then translates it into the machine code.
Example of C Keywords
In the following program, we are using a keyword as an identifier i.e., as the name of the user-defined function, that will cause a compilation error.
#include <stdio.h> void register(int, int); int main () { /* variable definition: */ int a=5, b=7; register(a,b); return 0; } void register(int a, int b) { printf("%d", a+b); }
Errors
main.c:3:15: error: expected identifier or '(' before 'int' 3 | void register(int, int); | ^~~ main.c: In function 'main': main.c:8:14: error: expected ')' before ',' token 8 | register(a,b); | ^ | ) main.c: At top level: main.c:12:15: error: expected identifier or '(' before 'int' 12 | void register(int a, int b) | ^
The reason for the errors is that we are using a keyword register as the name of a user-defined function, which is not allowed.
The ANSI C version has 32 keywords. These keywords are the basic element of the program logic. These keywords can be broadly classified in following types −
- Primary Data types
- User defined types
- Storage types
- Conditionals
- Loops and loop controls
- Others
Let us discuss the keywords in each category.
Primary Types C Keywords
These keywords are used for variable declaration. C is a statically type language, the variable to be used must be declared. Variables in C are declared with the following keywords:
int | Declares an integer variable |
long | Declares a long integer variable |
short | Declares a short integer variable |
signed | Declares a signed variable |
double | Declares a double-precision variable |
char | Declares a character variable |
float | Declares a floating-point variable |
unsigned | Declares an unsigned variable |
void | Specifies a void return type |
User-defined Types C Keywords
C language allows you to define new data types as per requirement. The user defined type has one or more elements of primary type.
The following keywords are provided for user defined data types −
struct | Declares a structure type |
typedef | Creates a new data type |
union | Declares a union type |
enum | Declares an enumeration type |
Storage Types C Keywords
The following set of keywords are called storage specifiers. They indicate the location where in the memory the variables stored. Default storage type of a variable is auto, although you can ask the compiler to form a variable with specific storage properties.
auto | Specifies automatic storage class |
extern | Declares a variable or function |
static | Specifies static storage class |
register | Specifies register storage class |
Conditionals C Keywords
The following set of keywords help you to put conditional logic in the program. The conditional logic expressed with if and else keywords provides two alternative actions for a condition. For multi-way branching, use switch – case construct. In C, the jump operation in an assembler is implemented by the goto keyword.
goto | Jumps to a labeled statement |
if | Starts an if statement |
else | Executes when the if condition is false |
case | Labels a statement within a switch |
switch | Starts a switch statement |
default | Specifies default statement in switch |
Loops and Loop Control C Keywords
Repetition or iteration is an essential aspect of the algorithm. C provides different alternatives for forming a loop, and keywords for controlling the behaviour of the loop. Each of the keywords let you form a loop of different characteristics and usage.
For | Starts a for-loop |
do | Starts a do-while loop |
while | starts a while loop |
continue | Skips an iteration of a loop |
break | Terminates a loop or switch statement |
Other C Keywords
The following miscellaneous keywords are also extremely important:
const | Specifies a constant value |
Sizeof | Determines the size of a data type |
Volatile | compiler that the value of the variable may change at any time |
In C99 version, five more keywords were added −
- _Bool
- _Complex
- _Imaginary
- inline
In C11, seven more keywords have been added
- _Alignas
- _Alignof
- _Atomic
- _Generic
- _Noreturn
- _Static_assert
When the C23 standard will be released it will introduce 14 more keywords −
- alignas
- alignof
- bool
- constexpr
- false
- nullptr
- static_assert
- thread_local
- true
- typeof
- typeof_unqual
- _Decimal128
Most of the recently reserved words begin with an underscore followed by a capital letter, Since existing program source code should not have been using these identifiers.
Following points must be kept in mind when using the keywords:
- Keywords are reserved by the programming language and have predefined meaning. They cannot be used as name of a variable or function.
- Each keyword has to be used as per the syntax stipulated for its use. If the syntax is violated, the compiler reports compilation errors.
- C is one of the smallest computer languages with only 32 keywords in its ANSI C version, although a few more keywords have been added afterwards.