Use in printf (C language)

Source: Internet
Author: User

#include <stdio.h>int main (int argc, const char * argv[]) {//Reshape output printf ("%d,%d", 3,4);    printf ("\ n");    The character width of the shaping output,%MD printf ("%4d,%4d", 3,4);    printf ("\ n");    Long shaping format output printf ("%ld,%ld", (Long) 3, (long) 4);    printf ("\ n");    Long shaping can also set the output character width of printf ("%8ld,%8ld", (Long) 3, (long) 4);    printf ("\ n");    Output%o int a =-1 in 8 binary format;    printf ("%d,%o", a,a);    printf ("\ n"); printf ("%d,%13o", a,a);    Sets the output width of the character//-1 in memory (in the form of a complement): eg:111111111 (the first bit is the sign bit) printf ("\ n");    x symbol output 16 binary int b =-1;        printf ("%x,%o,%d", b,b,b);    printf ("\ n");    U is unsigned output int c =-1;    unsigned int d = 65535;    printf ("%x,%o,%d,%u", c,c,c,c);    printf ("\ n");        printf ("%x,%o,%d,%u", d,d,d,d);    printf ("\ n");    c format characters, output a character char e = ' a ';        printf ("%c,%d", e,e);    printf ("\ n");    S-format character, used to output a string//char f[]= "China";//Prinf ("%s", f), #warning output string has a problem//f format character, used to output real numbers (including: single precision, double precision), Output in decimal form 1,%f format character, do not specify the width of the field, the system is automatically specified, so that the whole part of the output, and output 6 decimal places. Note: The number of outputsNot all the numbers in the word are valid digits, and the single-precision real number is usually 7 bits. The double-precision valid bit is 16 bits, giving the decimal 6 bits. float x,y;//x = 11111111.111;y=22222222,222;//printf ("%f \ n", x+y);    It can be seen from the results that only 7 bits are valid.    Double x, y;    x = 11111111.111;y=22222222.222;    printf ("%f \ n", x+y);    2,%M.NF, specify the output data for the Occupy M column, where the decimal bit n bit, if the value is greater than M, will be on the left no space.        3,%-m.nf and%m.nf are basically the same, just the value of the output to the left, the right side to fill the space. Symbol e, output in the form of an exponent//1,%e, does not specify the width of the output data, and the number of decimal places, and some C-compiler system automatically points out that the number is divided into 6 digits, the number of parts divided into 5 bits, (eg:+002) printf ("%e",    12389.454566);//And this system is the default stack of 4-bit printf ("\ n");    %m.ne and%-m.ne, m,n,-in the same way as in the front.    Double F = 123.456;    printf ("%e%10e%10.2e%.2e%-10.2e", f,f,f,f,f);    printf ("\ n");    The format character G, which is used to output a real number, automatically chooses the F format or the e format double g = 123.456, depending on the size of the numbers;    printf ("%f%e%g", g,g,g);    printf ("\ n");    Double h = 1234567123.456;        printf ("%f%e%g", h,h,h); Note: A format character starts with a% and ends with one of the preceding formatting characters.    can be inserted in the middle of additional modifiers, in fact, is the ordinary character//printf ("c=%cf=%fs=%s", c,f,s),//actually f= is the ordinary character printf ("\ n");        Output% symbol printf ("%f%%", 1.0/3);    GetChar (); return 0;}

The following is a picture of some of the corresponding format symbols output: output



The following is the use of the escape character "\"








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use in printf (C language)

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.