Page 172 - C-Language
P. 172
Conversion Type of
Description
Specifier Argument
truncated to length given by precision, if specified
prints void-pointer value; a nonvoid-pointer should be
p void* explicitly converted ("cast") to void*; pointer to object only,
not a function-pointer
% n/a prints the % character
write the number of bytes printed so far into the int pointed
n int *
at.
Note that length modifiers can be applied to %n (e.g. %hhn indicates that a following n conversion
specifier applies to a pointer to a signed char argument, according to the ISO/IEC 9899:2011
§7.21.6.1 ¶7).
Note that the floating point conversions apply to types float and double because of default
promotion rules — §6.5.2.2 Function calls, ¶7 The ellipsis notation in a function prototype
declarator causes argument type conversion to stop after the last declared parameter. The default
argument promotions are performed on trailing arguments.) Thus, functions such as printf() are
only ever passed double values, even if the variable referenced is of type float.
With the g and G formats, the choice between e and f (or E and F) notation is documented in the C
standard and in the POSIX specification for printf():
The double argument representing a floating-point number shall be converted in the
style f or e (or in the style F or E in the case of a G conversion specifier), depending on
the value converted and the precision. Let P equal the precision if non-zero, 6 if the
precision is omitted, or 1 if the precision is zero. Then, if a conversion with style E
would have an exponent of X:
• If P > X >= -4, the conversion shall be with style f (or F) and precision P - (X+1).
• Otherwise, the conversion shall be with style e (or E) and precision P - 1.
Finally, unless the '#' flag is used, any trailing zeros shall be removed from the
fractional portion of the result and the decimal-point character shall be removed if there
is no fractional portion remaining.
The printf() Function
Accessed through including <stdio.h>, the function printf() is the primary tool used for printing
text to the console in C.
printf("Hello world!");
// Hello world!
Normal, unformatted character arrays can be printed by themselves by placing them directly in
https://riptutorial.com/ 148

