首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

生手,求解

2013-04-20 
新手,求解#includestdio.hint f(int a,int b){int cif(ab)c1else if(ab)c0else c-1printf(%d

新手,求解
#include<stdio.h>
int f(int a,int b){
int c;
if(a>b)
c=1;
else if(a==b)
c=0;
else 
c=-1;
printf("%d,%d\n",a,b);
return (c);
main()
{
int i=2,p;
p=f(i,++i);
printf("%d",p);
}

是不是先传值在进行i++,那么a,b的值是多少?详细解释一下 函数传值
[解决办法]
a=3,b=3.
c语言函数参数处理顺序-从右向左,请参见文档:http://hi.baidu.com/j_persist/item/2d45e58d25e0cb5c850fab36

[解决办法]
f(i,++i)会先处理++i,之后再接受第一个i,所以i已经变成了3了。


引用:
a=3,b=3.
c语言函数参数处理顺序-从右向左,请参见文档:http://hi.baidu.com/j_persist/item/2d45e58d25e0cb5c850fab36

热点排行