So to use printf in our program we must include stdio. Once stdio. While programming, we often come to situation in which we need to print value of variable. Think of format specifier as a placeholder for some variable. In the above program, we first declared variable a as integer using int and b as floating or fractional number using float. If the value to be printed is shorter than this number, the result is padded with blank spaces.
The value is not truncated even if the result is larger. The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. For integer specifiers d , i , o , u , x , X : precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros.
The value is not truncated even if the result is longer. When no precision is specified, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed. The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. The argument is interpreted as a short int or unsigned short int only applies to integer specifiers: i, d, o, u, x and X. The argument is interpreted as a long int or unsigned long int for integer specifiers i, d, o, u, x and X , and as a wide character or wide character string for specifiers c and s.
The argument is interpreted as a long double only applies to floating point specifiers: e, E, f, g and G. If successful, the total number of characters written is returned. On failure, a negative number is returned. The flag adds a 0 prefix to non zero values. S : convert a string argument to OCaml syntax double quotes, escapes. C : convert a character argument to OCaml syntax single quotes, escapes. F : convert a floating-point argument to OCaml syntax dddd. Converts to hexadecimal with the flag see h.
Moreover, any trailing zeros are removed from the fractional part of the result and the decimal-point character is removed if there is no fractional part remaining.
B : convert a boolean argument to the string true or false b : convert a boolean argument deprecated; do not use in new programs.
0コメント