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++
// 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:
Output: 97

Input: D
Output: 68

Similar Reads

Using Type Conversion

Here int() is used to convert a character to its ASCII value. Below is the C++ program to implement the above approach:...

ASCII Value For Each Character in a String

Below is the C++ program to print the ASCII value of each character in a string:...

ASCII Value of All Characters

Below is the C++ program to print the ASCII value of all the characters:...