Open In App

C++ Program To Print ASCII Value of a Character

Improve
Improve
Like Article
Like
Save
Share
Report

Given a character, we need to print its ASCII value in C++. C++ Program To Print ASCII Value of a Character Examples :

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!


Last Updated : 19 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads