The printf Function
suggest changeprintf, declared in <stdio.h>, writes formatted text to stdout.
printf("Hello world!");
/* prints: Hello world! */
The first argument is the format string. Text that contains no conversion specifications is written as itself. A % in that string starts a conversion specification, except for %%, which writes one %. Passing a string that contains a conversion specification without a matching argument is undefined behavior.
printf("%d is the answer to life, the universe, and everything.", 42);
/* prints: 42 is the answer to life, the universe, and everything. */
int x = 3;
char y = 'Z';
char *z = "Example";
printf("Int: %d, Char: %c, String: %s", x, y, z);
/* prints: Int: 3, Char: Z, String: Example */
A conversion specification begins with % and a conversion specifier such as d, c, or s. It is not an escape sequence; escape sequences such as \n use a backslash. Arguments after the format string match the conversion specifications from left to right. Extra arguments are evaluated and otherwise ignored. A missing argument, or an argument of the wrong type, is undefined behavior. Each argument may be a literal or a variable.
On success, printf returns the number of characters written, as an int. On failure it returns a negative value.