printf("Hello World"); int value = 5; printf("Hello %d world\n", value); char c = 'a'; printf("val = %d c = %c\n", value, c); // format string tells // printf to first expect // an integer and then a char char[] world_str = "world"; printf("Hello %s\n", world_str);
Can you guess what happens if this piece of code is executed?
char[] world_str = "world"; printf("Hello %s\n"); // no second argument!
The format string tells printf to look for a string parameter which is not there - does printf recognize the mistake? Or will it just take something for a string pointer? The answer requires some knowledge about how c-functions work.