[an error occurred while processing this directive]
The printf statement
printf is C's basic command for formatted output.
Examples
printf("Hello world\n");
printf("%d + %d equals %d\n", x, y, x+y );
printf("%s\n", reply);
In general
printf( Format , E1 , E2, E3 ... En )
where
- Format evaluates to a string
- The expressions E1...En evaluate to the values V1...Vn
- There are n format codes (%'s) in Format
- Each Vi is substituted for the corresponding code in Format
Width, Precision and Alignment
- To restrict the number of characters printed the codes can take
a width and precision modifiers as in "%w.p<code>"
where w and p are integers.
- Width and precision have different meanings for for different
specifiers, for example %16.2f would print two characters to the right
of the decimal place in an output field which is at least 16
characters long.
- Alignment of the data within the overall width can be left (default)
or right.
printf format codes
code | type |
%c | character |
%d | signed integers |
%i | signed integers |
%e | exponential format |
%E | exponential format uppercase E |
%f | decimals |
%g | Use shortest of %e or %f |
%G | use shortest of %E or %f |
%o | octals |
%s | strings |
%u | unsigned integers |
%x | hexadecimals |
%X | hexadecimal with uppercase letters |
%p | pointers |
%% | the percent sign |
[an error occurred while processing this directive]
Saturday, 15-Feb-1997 15:23:15 EST