C programming language, developed in the early 1970s, remains a foundational language in computer science. Its simplicity and power make it ideal for system-level programming, embedded systems, and high-performance applications. One of the core aspects of C is its set of keywords. These reserved words have predefined meanings and cannot be used for variable names, function names, or any other identifiers.
Keywords in C
Here is a comprehensive list of keywords in C:
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
Evolution of Keywords Across C Versions
The original C language, also known as K&R C (after its authors Brian Kernighan and Dennis Ritchie), had a smaller set of keywords. As the language evolved, particularly with the ANSI C standard (C89/C90) and later the C99 and C11 standards, more keywords were introduced.
K&R C (1978)
The initial version of C included most of the keywords we know today. However, some features and corresponding keywords were added later.
ANSI C (C89/C90)
The ANSI C standard introduced some standardization and added keywords like const
, signed
, and void
.
C99
The C99 standard brought several new features, including:
inline
(for inline functions)restrict
(a type qualifier)
C11
The C11 standard, aimed at improving the language, added the _Atomic
keyword for atomic operations.
C18
While the C18 standard mainly focused on clarifications and corrections, it retained all the keywords from C11.
Detailed Explanation of Select Keywords
- auto: Declares automatic (local) variables. Rarely used in modern C programming.
- break: Exits from loops or switch statements.
- case: Specifies a block of code in a switch statement.
- char: Declares character-type variables.
- const: Declares variables whose value cannot be changed.
- continue: Skips the rest of the loop and starts the next iteration.
- default: Specifies the default block of code in a switch statement.
- do: Starts a do-while loop.
- double: Declares double-precision floating-point variables.
- else: Specifies the block of code to be executed if the if statement condition is false.
- enum: Declares an enumerated type.
- extern: Declares a variable or function defined in another file.
- float: Declares single-precision floating-point variables.
- for: Starts a for loop.
- goto: Transfers control to a labeled statement.
- if: Tests a condition and executes a block of code if the condition is true.
- int: Declares integer variables.
- long: Declares long integer variables.
- register: Declares register variables, which are stored in a CPU register.
- return: Exits from a function and optionally returns a value.
- short: Declares short integer variables.
- signed: Specifies a signed variable.
- sizeof: Returns the size of a variable or data type.
- static: Declares static variables, which retain their value across function calls.
- struct: Declares a structure, a user-defined data type.
- switch: Starts a switch statement for multi-way branching.
- typedef: Creates a new name for an existing type.
- union: Declares a union, a data type that can store different types in the same memory location.
- unsigned: Specifies an unsigned variable.
- void: Specifies that a function does not return a value.
- volatile: Declares variables that can be modified unexpectedly.
- while: Starts a while loop.
Conclusion
Understanding these keywords and their usage is crucial for mastering C programming. As the language evolves, staying updated with the latest standards ensures that you are using the most efficient and effective features available.
Happy coding!
Feel free to share your thoughts or ask any questions in the comments below.