' Number ': used to specify the minimum width of the print field, and if the width does not fit the result, the limit is automatically exceeded to use a wider field:
printf("this is %6d \n", 65);
Output: This is 65
'. Number ': Look at mate objects, if floating-point format specifiers such as%f, specify the precision of floating-point numbers, that is, the number of digits to the right of the decimal point, or%s, the maximum number of characters to print, and the integer format that specifies the minimum digits of the printed number (the precision of integers). ), not enough words with 0 to make a leading fill; if there is no number after the decimal point, the default is 0, which becomes an integer:
printf("this is /%.2f/\n", 65.3);
printf("this is /%.f/\n", 65.3);
printf("this is /%.3d/\n", 65);
Output: This is/65.30/
This is/65/
This is/065/
'-': minus, used to specify the alignment, from the above result we can see that the default alignment is right-aligned, and the use of '-', indicating to the left alignment:
printf("this is /%6d/\n", 65);
printf("this is /%-6d/\n", 65);
Output: This is/65/
This IS/65/
' + ': Prints the number of symbols, whether the number is exactly negative. In general, only with the use of symbolic format specifier, such as%+d,%+f, but%+u,%+c and so on will be error:
printf("this is %+c \n", 65);
Output: This is +65
': This is a space, the function and ' + ' are similar, the difference is to use a space instead of the printed ' + '; if used with ' + ', because of its lower priority, the effect will be overwritten by ' + ':
printf("this is /% -6d/\n", 65);
Output: this IS/65/
You can see that there is a space in front of 65.
' 0 ': For all number formats, fill in the blanks with a leading 0 instead of a space; if integer precision or '-' is specified, the flag is invalidated:
printf("this is /%05d/\n", 65);
' # ': used primarily to print octal or hexadecimal preamble symbols, occasionally with floating-point types:
printf("this is /%#5x/\n", 65);
printf("this is /%#5o/\n", 65);
Output: This is/0x41/
This is/0101/
Various modifiers for different numeric type conversions, which are used in conjunction with numeric type specifiers:
H: denotes a short or unsigned short, such as%hd
HH: Represents a signed char or unsigned char, such as%hhu%HHX
L: Represents a long or unsigned long, such as%lo,%ld
Ll:long long or unsigned long long,%llx
L:long Double
T: can only be used with integer types, indicating the type of difference between pointers, note that it is not the pointer type itself,%TD
Z: can only be combined with an integer type, which represents a size_t value, which is the type of sizeof return value,%ZD