C has no specific string concatenation operator (+
) like C# and Java. In C# or Java, when the compiler sees
"a" + "b"
it can compile the code exactly as if
"ab"
were written in the source code. In C, however, there is no similarly easy syntax for describing concatenation of strings that the compiler can recognise and pre-calculate. So the designers of C decades ago chose that
"a" "b"
would mean exactly the same thing as
"ab"
Naturally C++ inherited the same convention. While the standard C++ library overloads +
on std::string
to mean string concatenation, the compiler does not attempt to coalesce "a" + "b"
because that is actually an error (you can't add two const char *
pointers together).