Signup/Sign In

C++ Find the ASCII value of the Character Program

Hello Everyone!

In this tutorial, we will learn how to find the ASCII value of the given Character, in the C++ programming language.

Program Logic:

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:

Code:

#include <iostream>

using namespace std;

int main()
{
    //variable declaration - a char variable takes a single character as input
    char c;

    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";

    return 0;
}

Output:

C++ ascii

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 : )



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.