Skip to main content

Command Palette

Search for a command to run...

Ascii

Published
2 min readView as Markdown

ASCII value = Every character has a unique integer number assigned to it.

ASCII → American Standard Code for Information Interchange.

Computer doesn’t understand characters, it understands numbers.
So characters like 'A', 'B', 'a', '1', '*' are stored internally as numbers (0–127).


Simple Explanation

Example:

CharacterASCII Value
'A'65
'B'66
'a'97
'b'98
'0'48
'1'49
' ' (space)32

So when you write:

char x = 'A';
cout << (int)x;

Output: 65

Because 'A' is stored as ASCII 65 inside memory.


Why ASCII matters in C++?

✔ Characters are stored as integers

char type actually stores an integer (0–255).

✔ You can convert easily

char ch = 'a';
int val = ch;   // 97

✔ Comparison works using ASCII

if ('a' < 'b')  // true because 97 < 98

✔ A–Z and a–z are in sequence

  • 'A' → 65

  • 'Z' → 90

  • 'a' → 97

  • 'z' → 122

So uppercase and lowercase alphabets are stored consecutively.


✔ Example Program

#include <iostream>
using namespace std;

int main() {
    char ch;
    cin >> ch;

    cout << "ASCII value of " << ch << " is " << int(ch);
}

Input:

A

Output:

ASCII value of A is 65

More from this blog

Amit singh's blog

235 posts