% [标志位] [宽度] [精度] [数字长度] 说明符
#include <stdio.h>int main() { printf("Characters: %c \n", 'a'); printf ("Decimals: %d %+ld\n", -1977, 650000L); printf ("Preceding with blanks: %10d \n", 1977); printf ("Preceding with zeros: %010d \n", 1977); printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100); printf ("floats: %4.2f %+.0e %E \n", 3.1415, 3.1415, 3.1415); printf ("%s \n", "A string"); return 0;}
Characters: a Decimals: -1977 +650000Preceding with blanks: 1977 Preceding with zeros: 0000001977 Some different radices: 100 64 144 0x64 0144 floats: 3.14 +3e+00 3.141500E+00 A string类型转换隐式类型转换
变量前加上数据类型,并用圆括号包裹
(int)a
C编程基础-基础篇 2