Formatted string for C-language printf () function

Source: Internet
Author: User

Original link:
Https://www.runoob.com/cprogramming/c-function-printf.html

#include<stdio.h>#include<string.h>IntMain(void){Charc,S[20],*P;Inta=1234,*I;Floatf=3.141592653589;DoubleX=0.12345678987654321;P="Howdoyoudo";strcpy(S,"Hello,comrade");*I=12;C=' \x41 ';Printf("A=%d\n",A); /* Result output decimal integer a=1234*/Printf("A=%6d\n",A); /* Results output 6-bit decimal number a=1234*/Printf("A=%06d\n",A); /* Results output 6-bit decimal number a=001234*/Printf("A=%2d\n",A); /*a more than 2 bits, output by actual value a=1234*/Printf("*i=%4d\n",*I); /* Output 4-bit decimal integer *i=12*/Printf("*i=%-4d\n",*I); /* Output left-justified 4-bit decimal integer *i=12*/Printf("I=%p\n",I); /* Output Address i=06e4*/Printf("F=%f\n",F); /* Output floating-point number f=3.141593*/Printf("F=%6.4f\n",F); /* Output 6-bit floating-point number with 4 digits after the decimal point f=3.1416*/Printf("X=%lf\n",X); /* Output long floating-point number x=0.123457*/Printf("X=%18.16lf\n",X); /* Output 18-bit long floating-point number with 16 digits after the decimal point x=0.1234567898765432*/Printf("C=%c\n",C); /* Output character c=a*/Printf("C=%x\n",C); /* ASCII code value for output character c=41*/Printf("S[]=%s\n",S); /* Output Array string s[]=hello,comrade*/Printf("S[]=%6.9s\n",s); /* output a string of up to 9 characters s[]=hello,co*/     Printf "s=%p\n" ,s /* output array string first character address S=ffbe*/    printf "*p=%s\n" ,p/* output pointer string p=howdoyoudo*/    printf ( span class= "str" > "p=%p\n" ,p); /* the value of the output pointer P=0194*/    getch ();     return 0;}

Formatted string for the

C-language printf () function

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.