C++ Program to print ASCII value of a character

To find ASCII value of a Character in C++

Here, in this page we will discuss the program to find the ASCII value of a character in C++ .The variable of char data type can hold basically three types of characters:

  • Alphabets ( p, r, e, P, I, N, S, T, A…)
  • Digits (0, 1, 2, 3…)
  • Special Characters (@, $, &, *….)

These characters can be differentiated on the basis of ASCII value which have been assigned to them.

ASCII value of a character in C++

Did You Know:

ASCII or American Standard Code for Information Interchange is a binary code which is used by electronic equipment for electronic communications . A total of 128 character have been assigned values from 0-127
Between 65 to 90 and between 97 to 122 for Alphabets.
Between 48 to 57 for Digits.
All remaining for other characters.


Lets see how the code works

  • User gives an input
  • Input is stored in a char type variable say val.
  • val is converted from char to int .
  • The ASCII value of Character is Obtained
ASCII Value of a character

Code to print the ASCII value of character in C++ :

//C++ program to calcualte ASCII value of Character
using namespace std;

//main program
int main()
	char val;
	cout<<"Enter a character: ";

//printing the ASCII value of input 
 //through typecasting

cout<<"The ASCII value of "<<val<<" is "<<(int)val;
return 0;
Enter a character: $
The ASCII value of $ is 36