The C Programming language Chapter 4 Input and Output Basic Printf Conversions d decimal integer int a=567: printf(" %od, a) 567 x.X unsigend hexadecimal integer a=255: printf( %x, a) f unsigend octal integer inta=65 printf(%oo”a) 101 unsigend decimal integer int a=567: printf(%",a) 567 single character char a=65: printf("%oc", a) A M S string printf( %",ABC) ABC eE floating 例main 677890e+002 f floati f unsigned int uF65535 printf(u%od n", u) 567.789000 G 567.789 输出结果:u printf(90%) 111111111111111165535
The C Programming Language Chapter 4 Input and Output d,i decimal integer x,X unsigend hexadecimal integer o unsigend octal integer u unsigend decimal integer c single character s string e,E floating point (exponential form) f floating point (decimal form) g,G the shorter between f and e %% % Basic Printf Conversions int a=567;printf ( “%d”,a); 567 int a=255;printf(“%x”,a); ff int a=65;printf(“%o”,a); 101 int a=567;printf(“%u”,a); 567 char a=65;printf(“%c”,a); A printf(“%s”,“ABC”); ABC float a=567.789; printf(“%e”,a); 5.677890e+002 float a=567.789; printf(“%f”,a); 567.789000 float a=567.789; printf(“%g”,a); 567.789 printf(“%%”); % 例 main() { unsigned int u=65535; printf(”u=%d\n",u); } 输出结果:u=-1 11 11 11 11 11 11 11 11 65535
The C Programming language Chapter 4 Input and Output Modifies Modifies Function Specifies the minimum field width. >m, printed completely <m, padded on the left Specifies the number of digits after the decimal point of a floating-point value Specifies the maximum number of characters to be printed from a string Specifies left adjustment of the converted argument Specifies that the number will al ways be printed with a sign 0# Specifies padding to the field width with leading zero For o or x the first digit will be o or OX Before d, o, x, u, specifies long Before e, f, g, specifies double
The C Programming Language Chapter 4 Input and Output Modifies Function m Specifies the minimum field width. >m,printed completely ; <m ,padded on the left. .n Specifies the number of digits after the decimal point of a floating-point value. Specifies the maximum number of characters to be printed from a string. – Specifies left adjustment of the converted argument. + Specifies that the number will always be printed with a sign. 0 Specifies padding to the field width with leading zero. # For o or x ,the first digit will be 0 or 0x l Before d,o,x,u, specifies long Before e,f,g, specifies double Modifies