In C, a token is the smallest element of a program that is meaningful to the compiler.
C programs are made up of tokens combined to form statements and expressions.
The types of tokens in C are:
-
Keywords
-
Identifiers
-
Constants
-
Strings
-
Operators
-
Punctuation (Special Symbols)
1. Keywords
Keywords are reserved words that have a predefined meaning in C.
They cannot be used as identifiers (names of variables, functions, etc.).
Examples of C Keywords
Example in code
2. Identifiers
Identifiers are names given to variables, functions, or user-defined items.
They must follow rules:
-
Start with a letter or underscore (_)
-
Can contain letters, digits, and underscores
-
Case-sensitive (
ageandAgeare different) -
Cannot be a keyword
Examples
3. Constants
Constants are fixed values that do not change during program execution.
Types of Constants in C
-
Integer constants →
10, -5, 100 -
Floating-point constants →
3.14, -0.75 -
Character constants →
'A', 'z', '1' -
String constants →
"Hello", "C Programming"
Example
4. Strings
Strings are sequences of characters enclosed in double quotes " ".
Example
-
Strings are stored as arrays of characters ending with a null character
\0.
5. Operators
Operators are symbols that perform operations on variables and values.
Types of Operators
| Type | Examples |
|---|---|
| Arithmetic | + - * / % |
| Relational | == != > < >= <= |
| Logical | `&& |
| Assignment | = += -= *= /= %= |
| Increment/Decrement | ++ -- |
| Bitwise | `& |
| Conditional | ?: |
Example
6. Punctuation (Special Symbols)
Punctuation symbols are used to separate statements or group code in C.
Common Punctuation Symbols in C
| Symbol | Use |
|---|---|
; | Ends a statement |
{ } | Defines a block of code |
( ) | Function arguments, precedence |
[ ] | Array indices |
, | Separator for multiple items |
# | Preprocessor directives |
" | Start/end of string literals |
' | Start/end of character constants |
Example
✅ Summary
Tokens are the building blocks of a C program.
They include:
-
Keywords: Reserved words
-
Identifiers: Names of variables, functions
-
Constants: Fixed values
-
Strings: Sequences of characters
-
Operators: Perform operations
-
Punctuation: Special symbols to structure code
All C programs are built using these fundamental elements.