while (scanf("%d%d", &a, &b)==2)什么意思?
我很菜麻烦帮忙看下这里循环里的==2是什么意思intmain(){inta,b;while(scanf("%d%d",&a,&b)==2){printf("%d\n",a...
我很菜麻烦帮忙看下这里循环里的==2是什么意思
int main()
{
int a, b;
while (scanf("%d%d", &a, &b)==2)
{
printf("%d\n", a+b);
}
return 0;
} 展开
int main()
{
int a, b;
while (scanf("%d%d", &a, &b)==2)
{
printf("%d\n", a+b);
}
return 0;
} 展开
3个回答
展开全部
关于scanf的返回值,MSDN里是这样写的:
Both scanf and wscanf return the number of fields successfully converted
and assigned; the return value does not include fields that were read but
not assigned. A return value of 0 indicates that no fields were assigned.
The return value is EOF for an error or if the end-of-file character or the
end-of-string character is nocountered in the first attempt to read a character.
如:
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。
此外写成2 == scanf()格式是一种编程风格~防止由于程序员手误写成"="
Both scanf and wscanf return the number of fields successfully converted
and assigned; the return value does not include fields that were read but
not assigned. A return value of 0 indicates that no fields were assigned.
The return value is EOF for an error or if the end-of-file character or the
end-of-string character is nocountered in the first attempt to read a character.
如:
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。
此外写成2 == scanf()格式是一种编程风格~防止由于程序员手误写成"="
展开全部
scanf的返回值
scanf的返回值有后面的参数决定
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。
且返回值为int型.
该语句可以给你不断输入两个数,计算它们的和
scanf的返回值有后面的参数决定
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。
且返回值为int型.
该语句可以给你不断输入两个数,计算它们的和
参考资料: http://baike.baidu.com/view/1390039.htm
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看一下scanf函数的定义就知道了,scanf()函数返回成功赋值的数据项数(也就是读了多少个数据),读到文件末尾出错时则返回EOF。
scanf("%d%d", &a, &b) == 2 的意思就是判断是否正确地读入了2个数字
scanf("%d%d", &a, &b) == 2 的意思就是判断是否正确地读入了2个数字
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询