Tokens in C
In C programming, a token is the smallest individual unit in a program. The compiler breaks the code into these tokens for processing. The major types of tokens in C include:
a. Keywords
These are reserved words with special meanings in C. They cannot be used for naming variables or functions. Examples include int
, return
, if
, else
, while
, for
, break
, continue
, void
, and many more.
b. Identifiers
Identifiers are the names used for variables, functions, arrays, and structures. They must begin with a letter (A–Z or a–z) or an underscore and can be followed by letters, digits, or underscores. They are case-sensitive.
c. Constants
Constants are fixed values that do not change during the execution of a program. They can be:
- Integer constants (e.g., 10, -20)
- Floating-point constants (e.g., 3.14, -0.5)
- Character constants (e.g., 'A', 'z')
- String constants (e.g., "Hello", "C language")
d. Operators
Operators are symbols used to perform operations on variables and values. They include:
- Arithmetic operators (
+
,-
,*
,/
,%
) - Relational operators (
<
,>
,==
,!=
,<=
,>=
) - Logical operators (
&&
,||
,!
) - Assignment operators (
=
,+=
,-=
, etc.) - Bitwise, increment/decrement, and other miscellaneous operators
e. Special Symbols
Special symbols have specific uses in the structure and syntax of C programs. Examples include:
- Braces
{}
for defining blocks - Parentheses
()
for function calls and control statements - Square brackets
[]
for arrays - Semicolon
;
to end statements - Comma
,
for separating variables or function arguments - Asterisk
*
used in pointers or multiplication - Ampersand
&
used in referencing memory addresses