|
printf ( " format string " , value1, value2, ..... ); |
The "format string" contains instructions on how to interpret each of the values in the parameter list
|
Formatting character | Meaning |
---|---|
%d | Print the (next) value as a signed integer value |
%u | Print the (next) value as a unsigned integer value |
%ld | Print the (next) value as a long signed integer value |
%lu | Print the (next) value as a long unsigned integer value |
%f | Print the (next) value as a floating point value |
%lf | Print the (next) value as a double precision floating point value |
%o | Print the (next) value as a octal based number |
%x | Print the (next) value as a hexadecimal based number |
%p | Print the address as a hexadecimal based number |
%c | Print the (next) value as a character (i.e., used the ASCII code) |
%s | Print the (next) value as a string (will be explained much later) |
%% | Print a % character |
int main( int argc, char* argv[] ) { int x; x = 'A'; printf( "x = 'A': %d, %u, %c\n", x, x, x); x = 64; printf( "x = 64: %d, %u, %c\n", x, x, x); x = -1; printf( "x = -1: %d, %u, %c\n", x, x, x); } |
Output:
x = 'A': 65, 65, A x = 64: 64, 64, @ x = -1: -1, 4294967295, (FFFF is not a printable chracater) |
How to run the program:
|
|
|
How to run the program:
|