C++ Program to find ASCII Value of a Character

In this tutorial, you will learn how to find ASCII Value of a Character in C++. Before that, you need to have knowledge of the following in C++ programming.

ASCII stands for American Standard Code for Information Interchange. It is a 7-bit character set that contains 128 (0 to 127) characters. It represents the numerical value of a character.

Example: ASCII value for character A is 65, B is 66 but a is 97, b is 98, and so on.


C++ Program to find ASCII Value of a Character

#include <iostream>
using namespace std;

int main() 
{
 char ch;
 
 cout << "Enter a character: ";
 cin >> ch;
 
 cout << "ASCII Value of " << ch << ": " << int(ch);
 
 return 0;
}

Output:

//Run 1
Enter a character: q
ASCII Value of q: 113

//Run 2
Enter a character: Q
ASCII Value of Q: 81

In the above program to print ASCII value in C++, there is an explicit conversion of character into an integer. When the explicit conversion is performed to convert into an integer, its ASCII value is printed.