+ 2

How does this work?

Using templates, I added the sum of two characters 'A' and '1', the second as you see is number one. The result is 'r', same in code blocks. How does is work? https://code.sololearn.com/cIY28E1UOpzk/?ref=app

10th Dec 2019, 3:11 PM
Hilary
Hilary - avatar
4 ответов
+ 4
That code adds the ASCII values of the characters. The ASCII value of 'A' is 65 and the value of '1' is 49. The result is 114, the ASCII value of 'r'. That's why it prints 'r' Take a look at the ASCII table: http://www.asciitable.com
10th Dec 2019, 3:18 PM
Deroman
Deroman - avatar
+ 4
Deroman thanks. One more favor please, show me how to return the ASCII values of the characters.
10th Dec 2019, 3:26 PM
Hilary
Hilary - avatar
+ 4
char c = 'A'; int num = (int)c; cout << num; //Prints 65 or just: char c = 'A'; cout << (int)c; //Prints 65
10th Dec 2019, 3:38 PM
Deroman
Deroman - avatar
+ 2
Deroman thanks once again.
10th Dec 2019, 4:57 PM
Hilary
Hilary - avatar