Keywords are reserved words in C that have special meanings defined by the language. They are part of the C syntax and cannot be used as identifiers (variable names, function names, etc.). Here’s a detailed explanation of keywords in C:
Keywords are reserved words predefined by the C compiler that convey specific instructions. Since they are part of the language syntax, they must be used according to their intended functionality, and you cannot use them as names for variables or functions.
Below is a list of common keywords in the C language and their functions:
auto
: Used for automatic variable declarations (default behavior, rarely used explicitly).break
: Terminates the current loop or switch statement.case
: Defines a branch in a switch
statement.char
: Declares a character data type.const
: Defines constant values that cannot be modified.continue
: Skips the current iteration of a loop and moves to the next iteration.default
: Specifies the default block of code in a switch
statement if no case matches.do
: Starts a do-while
loop, which executes the loop body at least once.double
: Declares a double-precision floating-point number.else
: Defines the alternative block of code for an if
condition.enum
: Declares an enumeration, a user-defined type for named integer constants.extern
: Declares a global variable or function that is defined elsewhere.float
: Declares a floating-point data type.for
: Starts a for
loop, commonly used for iteration.goto
: Transfers control to a labeled statement (not recommended, as it makes code harder to read).if
: Used for conditional branching.int
: Declares an integer data type.long
: Declares a long integer, a larger version of int
.register
: Suggests storing the variable in a CPU register for fast access (modern compilers usually ignore this).return
: Exits from a function and optionally returns a value.short
: Declares a short integer, which uses less memory than int
.signed
: Declares a signed type, which can hold both positive and negative values.sizeof
: Returns the size of a data type or variable in bytes.static
: Defines the lifetime and visibility of a variable or function:struct
: Declares a structure, a collection of variables of different data types under a single name.switch
: A multi-way branching statement based on the value of a variable.typedef
: Defines an alias for an existing data type.union
: Declares a union, similar to a struct
, but members share the same memory space.unsigned
: Declares an unsigned type that can hold only positive values (or zero).void
: Declares a function that does not return a value or a pointer to "nothing."volatile
: Indicates that a variable’s value may be changed by something beyond the control of the code section in which it appears.while
: Starts a while
loop, which continues as long as the given condition is true.if
, else
, and return
:
int main() {
int a = 5;
if (a > 3) {
return 1;
} else {
return 0;
}
}
for
Loop:
for (int i = 0; i < 10; i++) {
printf("%d\n", i);
}
switch
Statement:
int day = 3;
switch (day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
default:
printf("Another day");
}
Mastering C keywords will allow you to control the flow of your program, define data, and perform various operations effectively.
@aCodeTutorials All Rights Reserved
privacy policy | about