C Keywords
C has a set of reserved keywords that define the syntax and structure of C programs. These keywords have specific meanings and cannot be used as names for variables, functions, or other identifiers, ensuring clarity and consistency in code.
C Keywords
C has a set of reserved keywords that are used to define the syntax and structure of C programs. These keywords have specific meanings and cannot be used for naming variables, functions, or other identifiers.
List of C Keywords
Below is a list of important C keywords along with their descriptions:
Keyword | Description |
---|---|
break |
Breaks out of a loop or a switch block. |
case |
Marks a block of code in switch statements. |
char |
A data type that can store a single character. |
const |
Defines a variable or parameter as constant (unchangeable). |
continue |
Continues to the next iteration of a loop. |
default |
Specifies the default block of code in a switch statement. |
do |
Used together with while to create a do/while loop. |
double |
A data type (usually 64 bits) that can store fractional numbers. |
else |
Used in conditional statements. |
enum |
Declares an enumerated type. |
float |
A data type (usually 32 bits) that can store fractional numbers. |
for |
Creates a for loop. |
goto |
Jumps to a line of code specified by a label. |
if |
Makes a conditional statement. |
int |
A data type (usually 32 bits) that can store whole numbers. |
long |
Ensures that an integer is at least 32 bits long. Use long long to ensure 64 bits. |
return |
Used to return a value from a function. |
short |
Reduces the size of an integer to 16 bits. |
signed |
Specifies that an int or char can represent both positive and negative values. |
sizeof |
An operator that returns the amount of memory occupied by a variable or data type. |
static |
Specifies that a variable in a function keeps its value after the function ends. |
struct |
Defines a structure (custom data type). |
switch |
Selects one of many code blocks to be executed. |
typedef |
Defines a custom data type using an alias. |
unsigned |
Specifies that an int or char should only represent positive values. |
void |
Indicates a function that does not return a value or specifies a pointer to a data with an unspecified type. |
while |
Creates a while loop. |
Example: Using C Keywords
Here is a simple example of how some C keywords are used in a program:
Example: Basic C Program with Keywords
#include <stdio.h>
int main() {
int x = 10;
if (x > 0) {
printf("x is a positive number.\n");
} else {
printf("x is a negative number.\n");
}
return 0;
}
Output:
Output
x is a positive number.
This program demonstrates the use of several keywords such as int
, if
, else
, and return
.