In earlier chapters, you learned two essential programming concepts: variables and data types. You also saw how different data types are declared using keywords like int, long, and float, and how to properly name variables.
Although keywords are part of the basic syntax of every programming language, this separate chapter helps you understand them clearly right after learning variables and data types.
Table of Contents:
What Are Keywords in Programming?
Keywords are predefined, reserved words that have special meaning within a programming language. These words are an essential part of that language’s syntax and cannot be used for any other purpose.
A crucial rule common to all programming languages is:
You cannot use a reserved keyword as a variable name, function name, class name, or identifier.
Example keywords:int, float, char, while, if, return, etc.
These keywords are used by the compiler or interpreter to understand what action the programmer intends to perform.
Why Can’t Keywords Be Used as Variable Names?
Keywords act as instructions for the language.
If you use them as variable names, the compiler will become confused and produce a syntax error.
Example of Incorrect Usage (C Programming)
#include <stdio.h>
int main() {
int float;
float = 10;
printf("Value = %d\n", float);
}
Error Message (C Compiler Output)
error: two or more data types in declaration specifiers
The error occurs because float is a reserved keyword.
Correct Example Using a Valid Variable Name
#include <stdio.h>
int main() {
int count;
count = 10;
printf("Value of count = %d\n", count);
}
This program compiles successfully because count is a valid identifier.
Reserved Keywords in Popular Programming Languages
programming keywords, reserved words in programming, C language keywords, Java keywords list, Python reserved words, keyword rules in programming, identifier restrictions, naming rules coding, what are keywords in programming, programming basics keywords
C Programming Keywords
Below are commonly used C keywords (not exhaustive):
| auto | else | long | switch |
| break | enum | register | typedef |
| case | extern | return | union |
| char | float | short | unsigned |
| const | for | signed | void |
| continue | goto | sizeof | volatile |
| default | if | static | while |
| do | int | struct | _Packed |
| double |
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, _Packed
Java Programming Keywords
These are frequently used keywords in Java:
| abstract | assert | boolean | break |
| byte | case | catch | char |
| class | const | continue | default |
| do | double | else | enum |
| extends | final | finally | float |
| for | goto | if | implements |
| import | instanceof | int | interface |
| long | native | new | package |
| private | protected | public | return |
| short | static | strictfp | super |
| switch | synchronized | this | throw |
| throws | transient | try | void |
| volatile | while |
abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while
Python Programming Keywords
Python uses a smaller set of highly expressive keywords:
| and | exec | not |
| assert | finally | or |
| break | for | pass |
| class | from | |
| continue | global | raise |
| def | if | return |
| del | import | try |
| elif | in | while |
| else | is | with |
| except | lambda | yield |
and, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield
Key Takeaway
You don’t need to memorize all keywords, but you must understand not to use them as variable names or identifiers. Always choose clear, readable names that do not conflict with reserved words in the programming language.
FAQ
1. What are keywords in programming?
Keywords are reserved words that have predefined meaning in a programming language and cannot be used as identifiers such as variable names or function names.
2. Why can’t I use a keyword as a variable name?
Because the compiler or interpreter already uses that keyword for a specific purpose. Using it as a variable name would create a syntax conflict.
3. Are keywords case-sensitive?
In most languages like C, Java, and Python, keywords are case-sensitive. For example, while is a keyword, but While is not.
4. Do all programming languages have the same keywords?
No. Each programming language has its own set of reserved keywords, although some may be similar in purpose (e.g., if, while, return).
5. How many keywords does Python have?
Python has around 33 keywords (depending on version), which are used to define the core structure of Python language syntax.
6. Where can I see the complete list of keywords in a language?
Most languages provide official documentation. For Python, help("keywords") in the Python shell prints the full list.