I am used to C# or Java.
How could the following statement be correct in C?
printf("aaa" "bbb");
On my Xubuntu 15.04 with GCC 4.9. It outputs:
aaabbb
And as I tried, below works too!
CHAR *p = "aaa""bbb""ccc";
printf(p);
It outputs:
aaabbbccc
I think there should be a comma but in that way, the first string will be treated as a format string. So, is this syntax legal?
Yes it is legal syntax because of translation phase 6 in ISO C99, #5.1.1.2 Translation phases:
- Adjacent string literal tokens are concatenated.
As mentioned adjacent strings are concatenated by the compiler. But if you want to see some difference you may add a \0
null terminator in your strings.
On adding the aaa\0
your o/p will be just aaa
as printf will print till it finds the 1st \0
null terminator.
#include<stdio.h>
int main()
{
printf("aaa\0" "bbb");
}
Output
aaa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With