[Solved] when i do printf(“%d”,’=’+’=’);, why it is showing 122.Please explain in details


In C, characters are represented internally using ascii. Characters are just numeric types, so adding them just adds the ascii* values. (Google ASCII for more info on this.)

In ascii, '=' is 61, so '=' + '=' is the same as 61 + 61, or 122, which is what you’re getting.

If you were hoping that + would concatenate a1 and a2, unfortunately that’s not the case, since chars are numeric values in C. If this is what you want, I’d google C strings (for how C handles strings) as a starting point.

If you were expecting it to do something else, I can edit my answer to explain that as well.

*EDIT: as pointed out by Fei Xiang, ASCII is not guaranteed by the C standard. However, on most modern systems, ASCII is used, and a similar answer to mine applies to your program regardless of the encoding used.

2

solved when i do printf(“%d”,’=’+’=’);, why it is showing 122.Please explain in details