C++ Program to Find ASCII Value of a Character

In this post, we will learn how to find the ASCII value of a character using C++ Programming language. But before that, let’s first learn about ASCII values.

ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard for electronic communication.

Each character or special character is represented by some ASCII Value, for example: the ASCII value of ‘A’ is 65.

In the below program, we will find the ASCII value of a character entered by the user.

So, without further ado, let’s begin this tutorial.

C++ Program to Find ASCII Value of a Character

// C++ Program to Find ASCII Value of a Character
#include <iostream>
using namespace std;

int main(){
    char ch;
    
    // Asking for input
    cout << "Enter a character: ";
    cin >> ch;
    
    // Displaying output
    cout << "ASCII Value of " << ch << " is: " << int(ch);
    return 0;
}

Output

Enter a character: F
ASCII Value of F is: 70

How Does This Program Work ?

    char ch;

In this program, we have declared a character data type variable named ch.

    // Asking for input
    cout << "Enter a character: ";
    cin >> ch;

The user is asked to enter a character. This entered character gets stored in the ch named variable.

    // Displaying output
    cout << "ASCII Value of " << ch << " is: " << int(ch);

The ASCII value of the entered character is found using the int() function.

Conclusion

I hope after going through this post, you understand how to find the ASCII value of a character using C++ Programming language.

If you have any doubt regarding the program, then contact us in the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *