Use of printf
1. Direct output of a text output result
printf ("Hello, world!\n"); "Hello, world!."
2. output int type data
int num=100;
printf ("%i\n", num); "Up" general output
printf ("%2i\n", num); " the"
printf ("%4i\n", num); Note that there are spaces at the beginning .
printf ("%-4i\n", num); Note that there are spaces at the end of the "
printf ("%04i\n", num); "0100"
Description
A the first letter of the INT data type Here I, indicating the output int type data
The 4 in front of B indicates the length of the output data and the space before the length is insufficient (by default)
The actual length of the C data is greater than the output length, whichever is true.
D to add a number before the output length, the length is padded at the end with a space
e If the output length is preceded by 0, indicating that the output length is insufficient in front of 0
3. Output Float type data
float floatvalue=10.0f;
printf ("%f\n", Floatvalue); "10.000000"
printf ("%.4f\n", Floatvalue); "10.0000"
Description
A f indicates output float type data
B. 4 indicates that decimal digits are reserved for four bits, followed by rounding
**c float data has a maximum of 6 decimal places and is inaccurate when the number of decimal places is greater than 6 o'clock
Usage details for printf (in Xcode development environment)