Character Set & Tokens in C
๐ป Character Set & Tokens in C (Easy Explanation)
When you write a C program, it is made using characters and tokens. Let’s understand both step-by-step ๐
๐น 1. Character Set in C
A character set means all the valid characters that can be used to write a C program.
✅ Types of Characters
๐ธ 1. Alphabets (Letters)
- A to Z (uppercase)
- a to z (lowercase)
๐ Example: a, B, x, Z
๐ธ 2. Digits (Numbers)
- 0 to 9
๐ Example: 0, 5, 9
๐ธ 3. Special Symbols
+ - * / % = < > ! & | ^ ~
( ) { } [ ] ; , . # _ " '
๐ธ 4. White Spaces
- Space
- Tab
- New line
๐ Used to make code readable
๐น 2. Tokens in C
Tokens are the smallest units (building blocks) of a C program.
๐ Example:
int a = 10;
Tokens are: int, a, =, 10, ;
๐น Types of Tokens
๐ธ 1. Keywords ๐
- Reserved words (special meaning)
- Cannot be used as variable names
๐ Examples:
int, float, if, else, return
๐ธ 2. Identifiers ๐ท️
- Names given to variables, functions
๐ Examples:
a, sum, totalMarks
๐ Rules:
- Cannot start with number
- No spaces
-
No special symbols (except
_)
๐ธ 3. Constants ๐ข
- Fixed values (do not change)
๐ Examples:
10, 3.14, 'A'
๐ธ 4. Strings ๐งต
- Group of characters inside double quotes
๐ Example:
"Hello"
๐ธ 5. Operators ➕
- Used to perform operations
๐ Examples:
+, -, *, /, =
๐ธ 6. Special Symbols ๐ฃ
-
Symbols like
;,{},()
๐น Simple Example Breakdown ๐ง
#include <stdio.h>
int main() {
int a = 5;
printf("Hello");
}
๐ Tokens:
-
Keywords:
int -
Identifiers:
main,a,printf -
Constants:
5 -
String:
"Hello" -
Symbols:
() { } ;
๐น Summary ๐
- Character Set = All valid characters
- Tokens = Smallest parts of program
Comments
Post a Comment