0
Why does it print an integer value when it is asked to print multiple characters (in single quotes)?
Please refer to the code attached. Compiler gave me a usual warning that multiple characters are there in single quotes. But the program compiles and it gives back an integer value. https://code.sololearn.com/cOInaQQ2VUP4/?ref=app
2 odpowiedzi
+ 6
value of multicaracter literals are implementation-defined.
multicharacter literal has type int, because it can't fit to char variable which has size only 1 byte. As it has type int your program prints integer value
An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value.
- 1
Maybe this could help.
https://www.sololearn.com/Discuss/67612/?ref=app
Edit. Adding from C++ tutorial.
https://www.sololearn.com/learn/CPlusPlus/1623/