C++ program to find character ASCII value
In this C++ program tutorial our task is to:
-
Write a C++ program to find the ASCII value of the given character.
C++ program to find the ASCII value of the given character
Given below is the C++ program in which a user input of char data type is accepted and then it is type casted to int data type and the following ASCII code is obtained.
#include<iostream>
using namespace std;
int main()
{
char s;
cout<<"Enter a character"<<endl;
cin>>s;
cout<<"The ASCII value of the given character is"<<endl;
cout<<int(s); //Type casted from char data type to int data type.
return 0;
}
OUTPUT :
Enter a character
a
The ASCII value of the given character is
97
EXPLANATION:
-
In the above code the compilation starts from the main function (here int main()) .
-
Then it takes a character as a input .
-
By typecasting the char data type to int data type.
-
When we change a character to its integer format then the ASCII value of the corresponding character gets printed out.
You can see the above code execution and output in codeblocks IDE:
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Sayantan Bose
- š Iām currently working on DS Algo skills
- š± Iām currently learning web develeopement
- šÆ Iām looking to collaborate with Oppia
- š« Reach me at https://www.linkedin.com/in/sayantan-bose-14134a1a6/
- š Pronouns: his/him
Page Views :
Published Date :
Aug 06,2020