C Tokens Overview
In C language, the smallest meaningful unit of a program is called a token. The compiler reads a C program token by token and then checks whether the program follows the rules of C syntax.
Tokens are the building blocks of a C program. Every statement in C is formed by combining tokens such as keywords, identifiers, constants, operators and special symbols.
Types of Tokens in C
| Token Type | Meaning | Examples |
|---|---|---|
| Keywords | Reserved words with fixed meaning | int, if, return |
| Identifiers | Names given by programmer | age, sum, studentName |
| Constants | Fixed values | 10, 3.14, 'A' |
| String Literals | Group of characters inside double quotes | "Hello", "C Notes" |
| Operators | Symbols used to perform operations | +, -, =, == |
| Special Symbols | Symbols used to separate or group code | ;, {}, (), [] |
Note:
Comments are not tokens. Comments are ignored by the compiler. They are written only to make the program easier to understand for humans.
Example:
#include <stdio.h>
int main() {
int num = 10;
printf("num is: %d", num);
return 0;
}
Output:
num is: 10
Explanation of Tokens:
intandreturnare keywords.-
numis an identifier andprintfis a predefined function name, so it is also treated as an identifier. =is an operator.10and0are constants."num is: %d"is a string literal.%dis a format specifier used to print integer values.;,()and{}are special symbols.
Real-Life Analogy:
Just like a sentence is made by combining words and punctuation marks, a C program is made by combining different tokens.
Summary:
- Tokens are the smallest meaningful units of a C program.
- C tokens include keywords, identifiers, constants, string literals, operators and special symbols.
- Every valid C statement is created by arranging tokens in correct order.