Tokens in C Programming Language
In C language, tokens are the smallest individual units of a program. The C compiler breaks a program into tokens to understand and compile it.
Types of C Tokens
There are 6 types of tokens in C:
1. Keywords
Keywords are reserved words with predefined meaning in C. They cannot be used as variable names.
Examples:
int, float, if, else, return, while
2. Identifiers
Identifiers are names given to variables, functions, arrays, etc.
Rules:
- Must start with a letter or underscore
- Can contain
letters,digits,underscore - Cannot be a keyword
- No spaces allowed
Examples:
total, _count, sum1
3. Constants
Constants are fixed values that do not change during program execution.
Types of constants:
- Integer constant:
10,-25 - Floating constant:
3.14,2.5 - Character constant:
'A' - String constant:
"Hello"
4. Operators
Operators are symbols used to perform operations.
Types:
- Arithmetic:
+ - * / % - Relational:
> < >= <= == != - Logical:
&& || ! - Assignment:
= += -= - Increment/Decrement:
++ --
5. Special Symbols
Special symbols help in program structure and syntax.
Examples:
{ } ( ) [ ] ; , #
6. Strings
A string is a sequence of characters enclosed in double quotes.
Example:
"C Programming"
Example Showing C Tokens
int sum = 10 + 20;Tokens used:
intKeywordsumIdentifier=Operator10,20Constants+Operator;Special symbol
Important Points
- Tokens are the basic building blocks of a C program
- Compiler reads programs token by token
- Understanding tokens helps in learning syntax easily
