C++ Program to Display ASCII Value of a Character
Problem
Write a C++ Program to Display ASCII Value of a Character.
Solution
In C programming, a character variable stores an ASCII value (an integer between 0 and 127) rather than the character itself. For example, ASCII value of ‘B’ is 66. This means that if you assign ‘B’ to a character variable, 66, rather than ‘B,’ is stored in that variable.
Here’s a sample C++ code snippet that displays ASCII Value of a Character.
#include <iostream> using namespace std; int main() { char c; cout << "Enter any Character : "; cin >> c; cout << "\nThe ASCII Value of Character = " << int(c)<<"\n"; return 0; }
Output

Leave Your Comment