输入的数据暂时放在缓冲区
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
printf("%d%d%d\n",a,b,c);
return 0;
}
运行结果
知识点总结
空格和回车和tap键都是被系统默认的输入方式
指定宽度的输入
#include<stdio.h>
int main()
{
int a,b;
scanf("%2d%3d",&a,&b);//2d是取两个实数
printf("%d %d\n",a,b);
return 0;
}
运行结果
知识点总结
%3.3f
第一3代表整个数的长度,第二个数代表小数位的长度
读取到某一地址
#include<stdio.h>
#include<stdlib.h>//该文件包含了的C语言标准库函数的定义
int main()
{
int a,b,*p;
p = &b;
scanf("%d%d",&a,p);//scanf读入的是a的地址
printf("%d %d",a,*p);
return 0;
}
运行结果
知识点总结
scanf读取的是a的地址,而不能是直接用a,指针则相反