12th Class NCERT Solution Download Click Here!

X




Sunday, 13 March 2016

Write a program which accepts a character and display its ASCII value.

#include<iostream>
using namespace std;

int main()
{
 char ch;
 cout<<"\nEnter any character : ";
 cin>>ch;
 cout<<"ASCII equivalent is : "<<static_cast<int>(ch);
 
 
 return 0;
}


OUTPUT:

Enter any character : A
ASCII equivalent is : 65

Hint: Here we used static_cast<int>(ch) .. Well static_cast is in built function in c++ . This function in simple english is converting a character (ch) into integer <int> which is also ASCII code for that character.


You will hardly get to ask the use of static_cast in class 12th. But you should better do more research for future references. 

No comments:

Post a Comment