#include <stdio.h>
int main() {
printf("%c + %c = %c\n", '2','3', '2' +'3'); //1
printf("%c + %c = %c\n", '2', '3', '2' + 3); //2
}
In 1, the ASCII value of 2 is 50 and the ASCII value of 3 is 51 so if you add it up, it's 101 and the ASCII character corresponding to 101 is e, so I understand that e came out.
In 2, there was no text corresponding to the Aski value of 53 and just 5 came out, so I'm asking why.
c++
The ASCII code value for '2'
is 50 and the ASCII code value for '5'
is 53.
'2' + 3
will be 55. You used %c
in printf()
so the character '5'
for 55 was printed.
Try the following:
printf("%c + %c = %c, %d\n", '2', '3', '2' + 3, '2' + 3); //2
© 2024 OneMinuteCode. All rights reserved.