I tried the following C code by accident:
char *str = "hello " "world";
It's right, but I can't understand. How to explain this instrument?
I tried the following C code by accident:
char *str = "hello " "world";
It's right, but I can't understand. How to explain this instrument?
According to the C Standard (5.1.1.2 Translation phases)
- Adjacent string literal tokens are concatenated.
So after this translation phase this code snippet
char *str = "hello " "world";
is adjusted to
char *str = "hello world";
As result the pointer str
points to the first character of the string literal "hello world"
.
C standard says these literals are to be concatenated.
More details in earlier answer: How does concatenation of two string literals work?