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

Popular posts from this blog

Introduction to Computer

History of Computer

Computer Generation