0

I have seen this way of using combination of strings in printf and scanf statements.

int a;
printf("Printing" "using" "multiple" "strings" "%d", a);
// The above is just an example, some usage that I saw was for printing specific integer types like int_32
// uint32_t var; printf("Value is %" PRTu32, var);

I always thought that we could only use a single string as a format specifier. Like as written in the definition of printf function it seems format can point to only one string.

int printf ( const char * format, ... );

So out of curiosity I tried the following code and it ran successfully!

char arr[] = "Hello " "World";
printf("%s",arr);      // Output - Hello World

Could anyone explain how this concatenation thing works and what is the correct way of doing it. Any help is appreciated.

Dhruv
  • 117
  • 11

1 Answers1

0

If you give a space or no space in between two string literals it concatenates the string literals.

That's one of the C feature: This is defined by the ISO C standard, adjacent string literals are automatically combined/concatinated into a single one.

Vijesh
  • 795
  • 3
  • 9
  • 23