C++ Program To Print ASCII Value of a Character
Last Updated :
19 Jul, 2022
Given a character, we need to print its ASCII value in C++. Examples :
Input: a
Output: 97
Input: D
Output: 68
C++ code: Here int() is used to convert character to its ASCII value.
CPP
#include <iostream>
using namespace std;
int main()
{
char c = 'A' ;
cout << "The ASCII value of " <<
c << " is " << int (c);
return 0;
}
|
Output:
The ASCII value of A is 65
Time complexity: O(1) since performing constant operations
Auxiliary Space: O(1)
Please refer complete article on Program to print ASCII Value of a character for more details!
Share your thoughts in the comments
Please Login to comment...