I'm learning c++ char type variable and what i learn is that sizeof(char) = 1 which means it can only hold 1 ASCII character. I'm using Visual Studio 2019 and Here's the strange behavior i've found:
char x = 'abcd';
std::cout << x; //it prints 'd', the last letter.
char y = 'dcba';
std::cout << y; //it prints 'a', the last letter.
surprisingly, it still compile and give the output as commented above. What is Visual Studio doing here? what's the logic behind outputting the last character?
However, when i do:
char x = 'abcde';
Visual Studio has warn me "too many characters in character constant", and cannot compile at all! Again, what's the logic here? If char cannot take more than 1 character, why does it still accept a input of length 1 to 4, but not anything more than 4?