Usage details for printf (in Xcode development environment)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.