Exercise:
Write a C++ program to find the ASCII value of any entered character.
Click Here to View the Solution:
#include <iostream>
using namespace std;
int main()
{
char x;
cout << "Insert any character: ";
cin >> x;
cout << "ASCII code of " << x << ": " << int(x);
return 0;
}
Click Here to View the Output:
Insert any character: $ ASCII code of $: 36
Click Here to View the Explanation:
- A character
char
type is requested from the user and saved asx
. This character is taken aschar
type. - The integer value of the
char
type is then printed on the screen explicitly. This prints the ASCII code of the character.