C语言常见易错点

1. 占位符概念

关于%.*f的格式化输出:(占位符的概念)
int a = 4;
float m = 3.14159;
printf(“%.*f\n”, a, m);

A. 3.1416
B. 3.14159
C. 4.000000
D. 运行错误还是什么的,不太记得了
解析:https://zhidao.baidu.com/question/2269588931158396988.html
所以上面的输出应该是A. 3.1416
#include <stdio.h> #include <stdlib.h> int main() { int a=1,b=2,c=3; printf("%d+%d=%*d",a,b,10,c); /* * format 标签属性是 %[flags][width][.precision][length]specifier * 其中,不确定的[width]或[.precision]可以将其中的数值用“*”代替。 * 而该值将被认为未指定,但是会作为附加整数值参数放置于要被格式化的参数之前。 */ return 0; } //输出是:1+2= 3

 

posted on 2022-05-19 20:33  蜀山菜鸟  阅读(66)  评论(0)    收藏  举报