Jul 2, 2016

C Programming #80: string literal concatenation

C Programming #80: string literal concatenation

This article details very tiny feature of C Programming language that is string literal concatenation. As we know constant string(string literal) are put in double quote in C. If there are two string placed side by side, with or without white-space then they are concatenated. Let us explore it by an example.


#include <stdio.h>
int main()
{
   char *p = "Hello "  "World";
   printf("p is %s\n", p);
   return 0;
}
p is Hello World

In the above program there are two string constants Hello and World which are placed side by side. Then the C concatenates them ignoring the white-space if any between the string constant. This comes in very handy if there is long strings that need to spread across several lines.

No comments :

Post a Comment