Given a character, we need to print its ASCII value in C++.
Input: a Output: 97 Input: D Output: 68
C++ code: Here int() is used to convert character to its ASCII value.
CPP
// C++ program to print // ASCII Value of Character #include <iostream> using namespace std;
// Driver code 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!