Print ASCII value of a character [C Plus Plus]

Below is the source code to print ASCII value of a character entered by the user.

CPP source code to print a character’s ASCII value

#include <iostream>
using namespace std;
int main()
{
 char character;
 //Input the character
 cout << "Type a character and hit ENTER: ";
 // Read the character
 cin >> character;
 // Print ASCII value of character
 cout << "ASCII Value of " << character << " is " << int(character);
 return 0;
}
Example output to print ASCII value of character g

Also Check C plus plus code to remove special characters from a string [C++]

Resource: https://en.cppreference.com/w/cpp/language/ascii

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published.