๐ C Keywords โ Reserved Words in C Programming
๐งฒ Introduction โ What Are Keywords in C?
Keywords in C are reserved words predefined by the language that have special meaning to the compiler. These words are part of the C syntax and cannot be used for naming variables, functions, or identifiers. They are essential for writing syntactically valid C programs and form the backbone of C language constructs like data types, control statements, and loops.
๐ฏ In this guide, youโll learn:
- The list of standard C keywords and their purpose
- How keywords are used in program structure
- Why you cannot redefine or use them as identifiers
- The difference between keywords and identifiers
๐ What Are C Keywords?
Keywords are built-in, reserved terms that are used to perform specific operations or define language constructs. The C compiler interprets them as commands rather than user-defined names.
๐ List of ANSI C (C89/C90) Keywords
Keyword | Purpose |
---|---|
auto | Declares automatic storage class |
break | Exits from a loop or switch |
case | Defines a case in a switch block |
char | Declares a character variable |
const | Declares a constant value |
continue | Skips to the next loop iteration |
default | Default case in a switch block |
do | Loop that executes at least once |
double | Declares a double precision float |
else | Executes if if is false |
enum | Declares an enumeration |
extern | Declares an external variable |
float | Declares a floating-point variable |
for | Looping construct |
goto | Jumps to a labeled statement |
if | Conditional execution |
int | Declares an integer variable |
long | Declares a long integer |
register | Declares a register variable |
return | Returns from a function |
short | Declares a short integer |
signed | Declares a signed variable |
sizeof | Returns the size of a variable |
static | Declares a static variable |
struct | Declares a structure |
switch | Multi-way branching |
typedef | Defines a new name for a type |
union | Declares a union type |
unsigned | Declares an unsigned variable |
void | Declares functions with no return |
volatile | Declares a volatile variable |
while | Looping construct |
๐งช Keywords Introduced in C99
Keyword | Purpose |
---|---|
inline | Suggests that a function be inlined |
_Bool | Boolean data type |
_Complex | Complex number type |
_Imaginary | Imaginary number type |
restrict | Optimizes pointer usage in functions |
๐งช Keywords Introduced in C11
Keyword | Purpose |
---|---|
_Alignas | Aligns variables in memory |
_Alignof | Returns alignment requirement of a type |
_Atomic | Atomic access for variables |
_Generic | Enables generic programming |
_Noreturn | Indicates functions that do not return |
_Static_assert | Compile-time assertion |
_Thread_local | Declares thread-local storage |
โ ๏ธ Rules for Using Keywords
- โ Cannot be used as variable, function, or identifier names
- โ
Must be written in lowercase (e.g.,
int
, notInt
) - โ Cannot be redefined or overridden
- โ Are recognized by the compiler as special symbols
โ Examples of Keyword Usage
int main() {
int age = 30; // 'int' is a keyword
if (age > 18) { // 'if' and 'return' are keywords
return 1;
}
return 0;
}
๐ Summary โ Recap & Next Steps
C keywords are reserved identifiers with fixed meanings that define how your program works. From declaring variables and types to controlling program flow, keywords play a vital role in every C application.
๐ Key Takeaways:
- C has 32 keywords in ANSI C, more in later versions like C99 and C11.
- Keywords are case-sensitive and cannot be used as identifiers.
- They are fundamental to all C syntax and logic structures.
- Knowing how and when to use keywords is essential for proper code flow.
โ๏ธ Real-World Relevance:
A strong grasp of C keywords enables efficient and error-free coding. They are foundational in systems programming, embedded development, and any C-based application.
โ Frequently Asked Questions (FAQ)
โ How many keywords are there in C?
โ
The original ANSI C (C89/C90) standard includes 32 keywords. C99 and C11 standards added additional keywords like _Bool
, inline
, _Atomic
, and others.
โ Can I use a keyword as a variable name?
โ No. Keywords are reserved and cannot be used for variable, function, or macro names. Doing so will cause a compilation error.
โ Are C keywords case-sensitive?
โ
Yes. C is a case-sensitive language. Int
, INT
, and int
are treated as different. Only int
is recognized as a valid keyword.
โ Can keywords be redefined or overridden?
โ No. Keywords have predefined meaning in the C language and cannot be redefined, overridden, or changed in any way.
โ What is the difference between a keyword and an identifier?
โ
A keyword is a reserved word used by the C language (e.g., return
, int
), while an identifier is a name defined by the programmer (e.g., count
, age
).
โ Are keywords the same across all C compilers?
โ All standard-compliant C compilers support the official list of keywords for each C version (C89, C99, C11). Some may include non-standard extensions, but these are not portable.
Share Now :