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