Reputation: 3293
In K&R, I saw an example where a string can be concatenated with a space"
char *s = "abc" "foo";
printf("%s", s); // prints "abcfoo"
How is space string concatenation different from using strcpy and strcat?
Upvotes: 0
Views: 97
Reputation: 158469
Adjacent string literal are concatenated by the pre-processor. From the draft C99 standard section 5.1.1.2
Translation phases paragraph 6:
Adjacent string literal tokens are concatenated
so it creates one string literal as a result.
Upvotes: 1
Reputation: 44250
Try: char *s = "abc" " " "foo";
BTW: it is not concatenation per se, it is just a method for initialising a string with a concatenation of a bunch of literals.
Upvotes: 1