常用的输出方式: 字符串 char str[] = "d 0 b"; //不包括空字符共5字节 printf("**%s**\n",str); //遇空字符结束 printf("**%7s**\n",str); //靠右 printf("**%-7s**\n",str); //靠左 输出结果: **d 0 b** ** d 0 b** **d 0 b ** int型 int a = 1234; printf("**%d**\n",a); printf("**%2d**\n", a); //靠右,宽度共2位,超过不受限 printf("**%5d**\n", a); //靠右,宽度共5位 printf("**%*d**\n", 5, a); //同上,可自定义宽度 printf("**%0*d**\n", 5, a); //同上,不够补0 printf("**%-*d**\n", 6, a); // 靠左,宽度共6位 输出结果: **1234** **1234** ** 1234** ** 1234** **01234** **1234 ** char型 char b = 'A'; printf("**%c**\n", b); //输出字符‘T’ printf("**%d**\n", b); //字符‘T’的ASCII码 printf("**%x**\n", b); //字符‘T’的ASCII码的16进制形式(小写) printf("**%X**\n", b); //字符‘T’的ASCII码的16进制形式(大写) printf("**%#x**\n", b); //字符‘T’的ASCII码的16进制形式且前置0x(小写) printf("**%#6x**\n", b); // 宽度共6位 printf("**%#06x**\n", b); // 宽度共6位,不够补0 输出结果: **A** **65** **41** **41** **0x41** ** 0x41** **0x0041** float型 float c = 1.2345678; printf("**%f**\n", c); //默认精度6位 printf("**%.7f**\n", c); //指定精度7位 printf("**%0.4f**\n", c); //指定宽度0位,超过不受限 printf("**%8.4f**\n", c); //指定宽度8位,包括小数点和精度位数 输出结果: **1.234568** //满5进1 **1.2345678** **1.2346** ** 1.2346**