C Tokens - Full Detailed Classification
1. Keywords
Definition: Reserved words in C with predefined meanings.
Features:
- All are lowercase.
- 32 standard keywords in ANSI C.
- Cannot be used as identifiers.
List: 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.
Example:
int num = 5; // 'int' and 'return' are keywords
2. Identifiers
Definition: Names given to variables, functions, arrays, structures, etc.
Rules:
- Must start with a letter or underscore.
- Can contain letters, digits, underscores.
- Case-sensitive.
- Cannot be a keyword.
Valid examples: total, sum_1, _maxValue
Invalid examples: 2num, float, a-b
3. Constants
Definition: Fixed values that do not change during execution.
Types:
1. Integer Constants:
- Decimal: 10, -45
- Octal: 017 (starts with 0)
- Hexadecimal: 0x1A, 0XFF
2. Floating-point Constants:
- Normal form: 3.14, -0.005
- Exponential: 1.2e3 (1.2 × 10³)
3. Character Constants:
- Single char in single quotes: 'A', '9'
- Escape sequences: '\n', '\t', '\0'
4. String Constants:
- In double quotes: "Hello", "C Language"
- Stored as char array ending with '\0'
Example:
const float PI = 3.1416; char newline = '\n';
4. Operators
Definition: Symbols that perform operations on data.
Categories:
1. Arithmetic: +, -, *, /, %
2. Relational: ==, !=, >, <, >=, <=
3. Logical: &&, ||, !
4. Assignment: =, +=, -=, *=, /=, %=
5. Increment/Decrement: ++, --
6. Bitwise: &, |, ^, ~, <<, >>
7. Misc: sizeof, ?:, ,
5. Punctuators
Definition: Symbols used to separate program elements.
Examples:
- ; → statement terminator
- {} → block of code
- () → function call/parameters
- [] → array indexing
- , → separator
- # → preprocessor directive
- "" and '' → string and char delimiters
Example:
#include
int main() { printf("Hello"); }
Summary Table
Token Type Description Examples
Keywords Reserved words with predefined meaning if, else, int
Identifiers Names for program elements sum, main, _value
Constants Fixed values 10, 3.14, 'A'
Operators Symbols for operations +, ==, &&
Punctuators Separators in code ;, {}, (), []