How i print the ascii code of an character with Cout ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How i print the ascii code of an character with Cout ?

29th Jan 2017, 4:08 PM
aziz
aziz - avatar
3 Answers
+ 5
Cast it to int Test: char a =44; cout << a << (int)a << endl;
29th Jan 2017, 4:59 PM
Mattias Eriksson
Mattias Eriksson - avatar
+ 7
If you don't want to output using cout, then you'll have to use printf(), which I highly not recommend.
29th Jan 2017, 4:44 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
printf("a = %d \n", 'a'); like this
29th Jan 2017, 8:27 PM
aziz
aziz - avatar