+ 5

Can anyone tell me how the output of this code is 55?

INT main() { INT x=3; char y='4'; cout<<x+y; return 0; }

4th Feb 2017, 9:05 AM
Shravan Kumar
Shravan Kumar - avatar
4 Answers
+ 2
I can. I am guessing you did this on purpose, but maybe not. the char 4 stores an int value of 52. normally if you were to cout the char 4 it would print 4, because that is how it handles the char value. Because you are adding it to an int it is adding the value of 52 and not the ascii representation of 52 which is 4 I like that problem
4th Feb 2017, 10:06 AM
Bill
Bill - avatar
+ 2
The ASCII code of char '4' is 52 (x34). The expression x+y convert char to int, so the result is 55. Hope this helpful. 😀
4th Feb 2017, 12:26 PM
zhenxi
zhenxi - avatar
+ 1
I didn't get you what's that 52 from where did that come
4th Feb 2017, 11:38 AM
Shravan Kumar
Shravan Kumar - avatar
+ 1
WA thanks
4th Feb 2017, 2:21 PM
Shravan Kumar
Shravan Kumar - avatar