How to use Type Conversion In C++
Here int() is used to convert a character to its ASCII value. Below is the C++ program to implement the above approach:
// 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)
C++ Program To Print ASCII Value of a Character
Given a character, we need to print its ASCII value in C++.
Examples:
Input: a
Output: 97Input: D
Output: 68
Contact Us