BCA Sem 1 | Unit 1 | Computer Concepts & C Programming
C Tokens Explained — BKNMU Junagadh
Keywords, Identifiers, Constants, Strings, Special Symbols, and Operators in C Language
The C compiler breaks every line of source code into 6 distinct token categories during the lexical analysis phase:
1. Keywords
32 reserved words with predefined meanings to the C compiler.
2. Identifiers
User-defined names for variables, functions, arrays, and structures.
3. Constants
Fixed values that do not change during program execution.
Examples of Every Token Category in Action
Here is a complete breakdown of all 6 token types with examples and compiler rules:
| Token Category | Definition & Role | Rules / Properties | Example Values |
|---|---|---|---|
Keywords | Reserved system words in C library | Must be written in lowercase; cannot be used as variable names | int, void, while, struct, return |
Identifiers | Names given to program elements | Must start with letter or _; case-sensitive; no spaces | main, rollNo, _count, avg_score |
Constants | Fixed literal values | Include Integer, Real (Float), Character, and Enum constants | 100, -45, 3.14159, 'Z' |
Strings | Sequence of characters enclosed in double quotes | Automatically terminated by a null character (\0) | "BKNMU Junagadh", "BCA Sem 1" |
Operators | Symbols that instruct CPU to perform operations | Arithmetic, Relational, Logical, Assignment, Bitwise | +, ==, &&, !=, =, ++ |
Special Symbols | Punctuation & structural syntax delimiters | Used to group statements, define blocks, and separate parameters | ;, ,, {, }, (, ), [, ], # |
Let's dissect a single C statement into its individual tokens:
C Code Statement:
Token Identification:
- Token Type: Keyword
- Specifies integer data type
- Token Type: Identifier
- User variable name
- Token Type: Operators
- Assignment & Addition
In total, the statement int total = 10 + 20; consists of 7 tokens: int, total, =, 10, +, 20, and ;.
First Character Rule
Must begin with an alphabet (A-Z, a-z) or an underscore (_). It CANNOT begin with a digit.
Allowed Characters
Can contain letters, digits (0-9), and underscores. No special symbols like $, @, or spaces allowed.
No Reserved Keywords
You cannot use any of the 32 C keywords (like for, if, float) as identifier names.
1st_rank is INVALID because it starts with a number. first rank is INVALID because it contains a space. first_rank is VALID!
- Definition: Smallest individual element of a C program recognized by the compiler.
- 6 Token Categories: Keywords, Identifiers, Constants, Strings, Special Symbols, Operators.
- Keywords Count: C has 32 standard ANSI keywords (e.g.,
int,char,goto,switch). - Identifiers: Names given to variables, functions, and arrays. Case-sensitive!
- Constants: Fixed values that cannot be modified during program execution.
- Strings: Character sequences in double quotes ending automatically with
\0. - Delimiters: Semicolon (
;) terminates statements; curly braces ({ }) group code blocks.