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);

}

Source code

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:

printf("%s %s\n", "Hello" "World!");
or
printf("%s %s\n", "HelloWorld!");

The result is that the first %s prints HelloWorld! and the second prints garbage.

Main gallery