[Solved] Why does a C++ pointer to char act as a character string despite the lack of a null terminator?


This operator+ is used here (a pointer to single char that is not null-terminated is not really suitable). Yes, most definitely undefined behavior.

lhs – string, character, or pointer to the first character in a null-terminated array

Just make std::string the common type to fix it:

((d == '\0') ? std::string("null character") : std::string(1, d))

And don’t form switchcase statements like that.

2

solved Why does a C++ pointer to char act as a character string despite the lack of a null terminator?