This program tries to print Hello World, but something not quite right comes out.
#include <stdio.h>
int main()
{
printf("%s %s\n",
"Hello"
"World!");
return (0);
}
Hint 1:
The first %s should print the first string to follow.
The second %s should print the second following string.
Hint 2:
The first %s does more than expected.
Hint 3:
The second %s does the unexpected.
Hint 4: The format is not followed by two string parameters.
Answer:
The problem is that there is no comma between
"Hello" and "World":
printf("%s %s\n", "Hello" "World!");
This is the same as:
orprintf("%s %s\n", "Hello" "World!");
printf("%s %s\n", "HelloWorld!");
The result is that the first %s prints HelloWorld!
and the second prints garbage.