C (and therefore C++ too) lets you create string literals by pasting several literals together. This is achieved by placing them adjacently. So "the quick brown fox" and "the quick" "brown fox" are 2 ways of specifying the same string literal. Note that this only works for string literals; you cannot expect C to give character arrays any special treatment.

What's it good for? Good question, but there are good reasons to use it:

  1. Split a long literal along several lines of code:
    printf("The rain it raineth on the just\n"
           "And also un the unjust fella.\n"
           "But chiefly on the just;\n"
           "For the unjust's stolen the just's umbrella.\n");
    
  2. Incorporate C preprocessor constants in the string:
    #define XYZ "letters"
    char xyz<> = "XYZ = \"" XYZ "\"";
    
    See also int32 for a real-world example.
  3. Incorporate stringified preprocessor values in the string. See #x and the stringize macro macro hack for examples.

Log in or register to write something here or to contact authors.