Convert Character Value to Corresponding ASCII Value

To convert a character to ASCII value we have to typecast it using int(character) to get the corresponding numeric value.

Example: 

C++




// C++ Program to convert
// Char to ASCII value
#include <iostream>
using namespace std;
 
int main()
{
    char c = 'g';
    cout << "The Corresponding ASCII value of 'g' : ";
    cout << int(c) << endl;
 
    c = 'A';
    cout << "The Corresponding ASCII value of 'A' : ";
    cout << int(c) << endl;
    return 0;
}


Output

The Corresponding ASCII value of 'g' : 103
The Corresponding ASCII value of 'A' : 65

C++ Char Data Types

A Char datatype is a datatype that is used to store a single character. It is always enclosed within a single quote (‘ ‘).

Syntax: 

Char variable;

Example:

C++




// C++ Program demonstrate
// Use of char
#include <iostream>
using namespace std;
 
int main()
{
    char c = 'g';
    cout << c;
    return 0;
}


Output

g

Similar Reads

ASCII Value

...

Convert Character Value to Corresponding ASCII Value

ASCII Value stands for American Standard Code for Information Interchange. It is used to represent the numeric value of all the characters....

Convert ASCII Value to Corresponding Character Value

To convert a character to ASCII value we have to typecast it using int(character) to get the corresponding numeric value....

Escape Sequence in C++

...