bscodinglab

Keywords and tokens

Keywords

In C language, a keyword is a reserved word that has a specific meaning and function in the language. Keywords cannot be used as identifiers, such as variable or function names.

 Examples :- keywords in C include if, else, while, for, switch, case, break, return, struct, union, typedef, enum, void, int, float, double, char, const, and volatile etc.

Tokens

A Token is the smallest individual unit of a program in C language. Tokens can be keywords, identifiers, operators, constants, or special symbols.

Examples :-  Tokens in C include x, +, 5.5, !=, and ;.

An identifier is a token that represents a variable, function, or other user-defined element in the program. Identifiers are created by the programmer and have a unique name that is used to refer to the element throughout the program. Operators are tokens that represent mathematical or logical operations, such as addition, subtraction, multiplication, division, and comparison.

Constants are tokens that represent fixed values that cannot be changed during the execution of the program. Constants can be either numeric or character constants. Numeric constants can be in decimal, hexadecimal, or octal format, while character constants represent individual characters enclosed in single quotes.

Keyword Token
Keywords are reserved words in a programming language that have a special meaning and purpose.
Tokens are the basic building blocks of a program, such as identifiers, literals, and operators.
Keywords cannot be used as variable names or identifiers.
Tokens can be used to form expressions, statements, and other constructs in a program.
Examples of keywords in C include "if", "else", "while", "for", and "def".
Examples of tokens include variable names like "x" and "y", numeric literals like "3.14" and "42", and operators like "+" and "-".
Keywords are predefined and cannot be changed or redefined by the programmer.
Tokens can be created and defined by the programmer as needed.
Keywords are used to define the structure and syntax of a programming language.
Tokens are used to represent data and operations in a program.

A list of 32 Keywords in the c language is given below

32 Keywords
Auto
Break
Case
Char
Const
Continue
Default
Do
Double
Else
Enum
extern
float
for
goto
if
while
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile

We will learn about all the C language keywords later While we create programs.

To summarize, keywords are a subset of tokens in C language. Keywords are reserved words with specific meanings and cannot be used as identifiers, while tokens can be any individual unit in the program, including keywords, identifiers, operators, constants, or special symbols