Char arithmetic | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Char arithmetic

please who knows what goes on when you perform mathematical algorithms with an integer and a char

4th Sep 2018, 12:03 PM
Jeffrey Onuigbo
Jeffrey Onuigbo - avatar
3 Answers
+ 4
Whenever you use type names like char, int/short/long etc., it's just a request to reserve a certain size of memory for your program. A char is one byte of memory and it can hold numerical values from 0 to 255 (unsigned) or -128 to 127 (signed). You don't necessarily have to use it for text characters like 'a', 'W' or '?', you can use it to store numerical values too (and do all sorts of calculations with them).
4th Sep 2018, 12:32 PM
Anna
Anna - avatar
+ 2
A char is an integer. So the same thing that would happen if you did any mathematical operation with 2 integers. See this table. http://www.asciitable.com/ For example, if you do something like 'A' + 5 you'd get 70. Because 'A' is the same as 65 and 65 + 5 = 70. 125521 / 'n' would be 1141, because 125521 / 110 = 1141.
4th Sep 2018, 12:11 PM
Dennis
Dennis - avatar
+ 1
http://www.asciitable.com/ Each char has an integer representation. When your perform arithmetics on chars, you actually perform them on their integers.
4th Sep 2018, 12:12 PM
Steppenwolf
Steppenwolf - avatar