Format character D C S F

Source: Internet
Author: User

    1. D format character: used to output a signed decimal integer

      D The previous number indicates the width of the field (the number of columns), such as%5d specified data accounted for 5 columns, the output of data in 5 columns of the right

      If the output is long, add the letter L, which is%ld before D.

    2. C format character: used to output one character

      The number before C also indicates the width of the field, with D.

Char ch= ' a ';p rintf ("%c", ch);//Run output a
printf ("%5c", ch);//output a,a preceded by 4 spaces
Char c= '? '; printf ("%d%c", c,c);//output result 63?

3. s format character: used to output a string

printf ("%s", "China"); Export China

4. f Format character

1>%f

The integer part of the real number is all output, and the fractional part outputs 6 bits.

Double a=1.0; printf ("%f\n" A/3);//Run Result: 0.333333//Although a is double precision, A/3 is also double precision but%f format can only output 6 bits

2>%m.nf

Specify data width and scale, such as%7.2f for data 7 columns, where decimals is 2 bits

printf ("%20.15f\n", A/3); Output: 0.333333333333333,//with 3 spaces in front of 0

And a double precision can only guarantee the accuracy of 15 digits of valid digits. Float can only guarantee 6-bit

This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1706108

Format character D C S F

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.