+ 5

Char datatype with cout

why output of below code is e? char c = 'abcde'; cout << c; additionally, I am confused that how one can consider 5 characters as single character being enclosed within single quote.

14th Mar 2018, 1:23 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 5
This isn't definitive, as I could not find any canonical reference, but it looks like what's happening is the compiler is creating a char type in memory then repeatedly writing over the top of it, so only the final character ends up written to the char variable. This is only an educated guess, however. Let me know if this ends up being confirmed.
18th Mar 2018, 9:13 AM
Peter David Carter
Peter David Carter - avatar
+ 2
Peter David Carter it looks like it is doing same as you have mentioned. See it I compiler dependent things some compiler gives warning and some strict compiler will treat it as error, but at the end it is programmers mistake.
30th May 2018, 10:11 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar