本帖最后由 gmadong@163.com 于 2014-4-26 08:29 编辑
//你的写法
int sumAndMinus(int a, int b, int *m){
*m =a-b;
return a+b;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
int *minus = 0;//这是定义一个指向int的指针所以 应该int minus =0;
int sum =sumAndMinus(10, 5, minus);//要在另一个函数中改变一个数的值应该传指针过去int sum =sumAndMinus(10, 5, &minus);
printf("minus =%d,sum =%d\n",minus,sum);
}
return 0;
}
//正确的写法
int sumAndMinus(int a, int b, int *m){
*m =a-b;
return a+b;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
int minus = 0;
int sum =sumAndMinus(10, 5, &minus);
printf("minus =%d,sum =%d\n",minus,sum);
}
return 0;
}
|