Computer Programming – Keywords

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.


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):

autoelselongswitch
breakenumregistertypedef
caseexternreturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_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:

abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfinalfinallyfloat
forgotoifimplements
importinstanceofintinterface
longnativenewpackage
privateprotectedpublicreturn
shortstaticstrictfpsuper
switchsynchronizedthisthrow
throwstransienttryvoid
volatilewhile

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:

andexecnot
assertfinallyor
breakforpass
classfromprint
continueglobalraise
defifreturn
delimporttry
elifinwhile
elseiswith
exceptlambdayield

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.

Related Article
Computer Programming Tutorial for Beginners – Learn Coding Step by Step (C, Python, Java)

Computer Programming Tutorial for Beginners – Learn Coding Step by Step Computer programming is the process of writing a series Read more

Computer Programming Overview

Computer Programming Overview Computer programming begins with understanding what a computer program is and how it operates. A computer program Read more

Computer Programming Basics

Computer Programming – Basics Understanding computer programming begins with learning the foundational building blocks that every programming language is built Read more

Computer Programming Environment

Computer Programming – Environment Before writing your first computer program, you must prepare the correct programming environment. Although the environment Read more

Computer Programming – Basic Syntax

Before diving into advanced programming concepts, it’s important to understand how basic syntax works in different Computer Programming languages. Syntax Read more

Computer Programming – Data Types

Data types are one of the most important concepts in programming. A data type defines the kind of data a Read more

Computer Programming Variables

In any programming language, a variable is one of the most fundamental concepts. A variable acts as a named storage Read more

Computer Programming – Basic Operators

Basic Operators In every programming language, operators are the symbols used to perform operations on values and variables. Think of Read more

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments