printf()中*的作用
在printf()中*充当变量的占位符
/*使用变量控制输出字符宽度*/
#include <stdio.h>
int main(void)
{
unsigned width,precision;
int number = 256;
double weight = 243.67;
printf("Enter a field width:\n");
scanf("%d",&width);
printf("The number is :%*d\n",width,number);
printf("Enter a width and a precision:\n");
scanf("%d%d",&width,&precision);
printf("weight = %*.*f\n",width,precision,weight);
return 0;
}
运行示例
scanf()中*的作用
把*放在%和转换字符之间时,会使得scanf()跳过相应的输入项。
\*跳过输入中的整数*\
#include <stdio.h>
int main(void)
{
int n;
printf("please input three integers:\n");
scanf("%*d,%*d,%d",&n);
printf("the last integer is :%d\n",n);
return 0;
}
运行示例
本文深入讲解了printf与scanf函数的功能及用法,特别是在printf中如何使用*作为变量占位符来控制输出宽度,并介绍了scanf中*的作用是跳过相应的输入项。
1155

被折叠的 条评论
为什么被折叠?



