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 the same ability to 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. The width of the field is not specified, and the system is self-specified, making the integer part all output, and outputting 6 decimal places.

Note: Not all numbers in the output numbers are valid numbers, and single-precision real-number digits are usually 7 bits.

The double-precision valid bit is 16 bits. Give 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 to occupy M column. When the decimal digit is n bits, the value is assumed to be greater than M. There will be no space on the left. 3,%-m.nf and%m.nf are basically the same. Just the value of the output to the left, and the right side to fill the blanks. The 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-compiling system itself to indicate that the number is a small number is divided into 6 bits, 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 is used to output a real number, which chooses the F format or e format double g = 123.456 According to 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%, ending with one of the above formatting characters.

The middle is able to insert additional modifiers, in fact the ordinary characters//printf ("c=%cf=%fs=%s", c,f,s);//In fact f= is the ordinary character printf ("\ n"); Output% symbol printf ("%f%%", 1.0/3); GetChar (); return 0;}

The following is a picture of some format symbol output: output



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








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.