C++ Find the ASCII value of the Character Program
In this tutorial, we will learn how to find the ASCII value of the given Character, in the C++ programming language.
This can be done easily by making use of the concept of Type-Casting.
Type-Casting refers to changing the data type of the variable while accessing it.
Example: If a variable
v is of type double, it's integral value can be accessed by the following code:
int a = (int) v;
For better understanding, refer to the code given below:
using namespace std;
//variable declaration - a char variable takes a single character as input
cout << "\n\nWelcome to Studytonight :-)\n\n\n";
cout << " ===== Program to Find the ASCII value of a character ===== \n\n";
//take user input
cout << "Enter a character : ";
cin >> c;
//printing the ASCII value of the entered character
cout << "\nThe ASCII value of the entered character is : " << (int)c << "\n\n";
We hope that this post helped you develop a better understanding of the concept of finding the type-casting in determining the ASCII value of the character, in C++. For any query, feel free to reach out to us via the comments section down below.
Keep Learning : )