Keywords in C: Understanding the Building Blocks of the Language
Keywords are an essential part of any programming language, including C. These reserved words have a specific meaning within the language and cannot be used as identifiers or variable names. In this article, we will explore the keywords in C, their uses, and some examples of how they are used in code.
Keywords in C
Keywords in C are reserved words that have specific meanings and cannot be used as identifiers. They are essential for the structure and functionality of the language.
List of Keywords in C:
Keyword | Description |
---|---|
auto |
Declares automatic storage duration for variables. |
break |
Exits a loop or switch statement. |
case |
Used within a switch statement to specify a case. |
char |
Defines a character data type. |
const |
Declares a constant value. |
continue |
Skips the rest of the current iteration in a loop. |
default |
Used within a switch statement as the default case. |
do |
Used with while to create a do-while loop. |
double |
Defines a double-precision floating-point data type. |
else |
Used with if to specify the alternative code block. |
enum |
Defines an enumeration data type. |
extern |
Declares variables or functions defined externally. |
float |
Defines a single-precision floating-point data type. |
for |
Used to create a for loop. |
goto |
Used to jump to a labeled statement. |
if |
Used for conditional statements. |
int |
Defines an integer data type. |
long |
Defines a long integer data type. |
register |
Suggests to the compiler to store a variable in a register for faster access. |
return |
Returns a value from a function. |
short |
Defines a short integer data type. |
signed |
Defines a signed integer data type. |
sizeof |
Returns the size of a data type or variable. |
static |
Declares static storage duration for variables or functions. |
struct |
Defines a structure data type. |
switch |
Used for conditional branching based on a value. |
typedef |
Creates an alias for an existing data type. |
union |
Defines a union data type. |
unsigned |
Defines an unsigned integer data type. |
void |
Indicates no return type or a function that doesn’t return a value. |
volatile |
Indicates that a variable’s value can be changed by external factors. |
while |
Used to create a while loop. |
Key Points:
- Keywords are reserved words and cannot be used as identifiers.
- They have specific meanings and functions within the C language.
- Understanding keywords is essential for writing correct and efficient C code.