嵌入式软件工程师&&太极拳
全部博文(548)
分类:
2011-02-20 20:06:41
#includeint main(void) { int i = 5687; printf("i = %d \n", i); printf("i = %10d \n", i); //设置字宽为10; 如果数字不足10个前补空格; 右对齐; printf("i = %-10d ", i); //左对齐; printf("i = %010d \n", i); //补0; double f = 1.3456789; printf("f = %lf \n", f); printf("f = %2.5lf \n", f); //小数点前保留2位有效,后面5位有效; printf("f = %*.*lf \n", 4, 3, f); printf("f = %.4lf \n", f); float ff = 12.45f; printf("ff = %lf \n", ff); //隐式转换; i = 'c'; //'c' ==> 默认转换为int ==> 再做赋值操作; int sum ; sum = i + '6'; //'6' ==> 整形; sum = 12 + 12.45; //12 ==> double 12.00 + 12.45 ==> 24.45 //24.45 ==> int printf("sum = %d \n", sum); sum = (int)24.45; //(类型)强制类型转换; printf("sum = %d \n", sum); char * p = (char *)0x12345678; return 0; }