C++ da int va char Casting

Published: (February 9, 2026 at 03:47 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Harfdan Songa (Char ➡️ Int)

Agar siz char (belgi) turidagi o’zgaruvchini int (butun son) ga aylantirsangiz, kompyuter o’sha belgining ASCII jadvalidagi tartib raqamini ko’rsatadi.

'A' = 65
'a' = 97
'0' = 48   // raqamning o'z kodi bor!
char harf = 'A';
int kod = harf;

cout << "Harf: " << harf << endl;   // Natija: A
cout << "Kodi: " << kod << endl;    // Natija: 65

Sondan Harfga (Int ➡️ Char)

Xuddi shunday, butun sonni char turiga aylantirib, unga mos keladigan simvolni topish mumkin:

int raqam = 98;
char belgi = raqam;

cout << "Son: " << raqam << endl;    // Natija: 98
cout << "Belgi: " << belgi << endl;  // Natija: b
0 views
Back to Blog

Related posts

Read more »

11. C# (Parsing)

The Real Goal of This Lesson The goal of this lesson is not to memorize int.Parse; the real point is to understand that a computer never trusts user input. Par...

10. C# (Static Typing vs Dynamic Typing)

The Real Goal of This Lesson This lesson is not about deciding whether static typing is “better” or “worse”. The real goal is to understand when and why the C...