Write a C++ Program to Find ASCII Value of a Character

In C++, characters are represented by their ASCII values, which are unique numeric codes assigned to each character in the ASCII character set.

The ASCII code for a character can be found using the built-in functions of C++.

To find the ASCII value of a character in C++, you can use the following code:

#include <iostream>
using namespace std;

int main()
{
    char c;
    cout << "Enter a character: ";
    cin >> c;
    cout << "The ASCII value of " << c << " is " << int(c);
    return 0;
}

In this code, we declare a variable c of type char to store the character input by the user.

Then we prompt the user to enter a character using the cout statement and receive the input using the cin statement.

Finally, we use the int(c) function to convert the character into its corresponding ASCII value, which is then printed to the console using the cout statement.

Note that the ASCII value of a character is an integer, so we must use the int data type to store the ASCII value.

In conclusion, finding the ASCII value of a character in C++ is a simple process that can be achieved using the int(c) function.

This functionality is useful for a variety of programming applications, such as encryption, compression, and data storage.