0

I encountered the following type of string literal in an open source library, which I have not seen before. It turns out that a and b are the same. I'm confused why the syntax of a is correct? Does C preprocessor concatenate two strings automatically?

#include<stdio.h>

int main()
{
const char a[] =
"123\r\n"
"123\r\n";

const char b[] = "123\r\n123\r\n";

printf(a);
printf(b);
}
qweruiop
  • 3,156
  • 6
  • 31
  • 55

2 Answers2

1

From section 5.1.1.2.6 of the C99 standard:

Adjacent string literal tokens are concatenated.

So your assumption is correct. Anyplace you see string literals consecutively, the compiler implicitly concatenates them.

dbush
  • 205,898
  • 23
  • 218
  • 273
0

Te declaration

const char a[] =
"123\r\n"
"123\r\n";  

is equivalent to

const char a[] = "123\r\n123\r\n";
haccks
  • 104,019
  • 25
  • 176
  • 264