fastread homefastrread library fastread menu

C++ : Find ASCII Value of a Character

Tutorial by:Manisha Dubey      Date: 2016-06-18 04:21:24

❰ Previous Next ❱

Every character in C++ programming is given an integer value to represent it. That integer value is known as ASCII value of that character. For example: ASCII value of 'a' is 97. When a character is stored in variable of type char, the ASCII value of character is stored instead of that character itself. For example: If you try to store character 'a' in a char type variable, ASCII value of that character is stored which is 97.

In, this program user is asked to enter a character and this program will display the ASCII value of that character.

Source Code


/* Source code to find ASCII value of a character entered by user */

#include <iostream>

using namespace std;

int main(){
 char ascii;
 cout << "Enter a character: ";
 cin >> ascii;
 cout << "Its ascii value is: " << (int) ascii << endl;
 return 0;
}

 

 
 

Output

Enter a character: G
Its ascii value is: 71

In this program, user is asked to enter a character and this character will be stored in variable ascii, i.e., the ASCII value of that character is stored in variable ascii. This character will then be converted into its equivalent ASCII value.

❰ Previous Next ❱


C++

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website