printf("You input values %d and %d\n", x, y);
If the value of x is 5 and y is 10, this printf statement will output:
You input values 5 and 10
- "You input values %d and %d\n" is the format string
- %d is a format specification
- The two format specifications %d are replaced in left to right order by the remaining values in the argument list: x and y
- The value to replace a %d conversion specification should be an integer.
Other conversion specifications:
Conversion spec | Expected value type |
---|---|
%d | int |
%f | float or double |
%c | char |
%s | char array1 |
1For the %s format, the char array is expected to have an entry containing the null character, '\0', that indicates the end of the character string. The printf function keeps printing successive characters until it finds this null character.