Problem is site you used for testing.
As I showed in comment your code doesn't hangs on:
Problem is on site cpp.sh site.
Most probably this site is configured to assume UTF-8 encoding in application output.
Now when you do addition of char
characters are promoted to int
that is why 195
is printed in earlier line. Your Sum
clips this results to char
type (here is undefined behavior since there is integer overflow).
Now in UTF-8 this byte 195
represents is an indicator that current character is build from two bytes. Your program never sends next byte. This site should be able to handle malformed UTF-8 and noticed that stream has ended and not wait for next character. It waits for this character and as a result it hangs. So this is a bug of site cpp.sh
.