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;
}
运行示例