+ 1
write a c++ to ASCII code in given given Character.
#include<iostream> using namespace std; int main() { char ch; int ASCII; cout<<"Enter a character: "<<endl; cin>>ch; ASCII=ch; cout<<"ASCII code is: "<<ASCII<<endl;; return 0; } output Enter a character: A ASCII code is: 65
12 Respostas
+ 2
@Vedant: Your example is almost perfect. Just don't use the nasty C casting operator. Using static_cast is more expressive, less error-prone and easier to read.
+ 1
use conio header functions to store the entered value in an integer data type variable and then display it
it will be shorter and may grab you better marks if you write it in exams
+ 1
and plus there is no need to store
ch into ASCII
just explicitly convert it into int while writing the cout object operation
+ 1
//assuming you know the basics part jumping directly to logic
char ch;
cout<<"Enter a character: "<<endl;
cin>>ch;
cout<<"ASCII code is: "<<((int)ch)<<endl;;
return 0;
0
nice
0
I want to learn
0
can you teach me
0
thanks.. my english is not good,so I can't properly to teach you
0
and I'm new user of c++..
0
thank you Vadant Patadia bro
0
@Stefan...the C operators are error prone only when fiddled in wrong...in here I'm just converting char to int type meaning smaller to bigger which is safe
plus sometimes C operators are short and take less space in the make hence for big programs like 8k to 30k lines of code you can use them to shorten the code for less compile time
0
static_cast<char>(ch);