您的位置:首页 > 其它

当函数的参数中包括变量,而又想在函数执行时,改变该变量的值,使其返回,应该用指针

2012-05-10 10:14 369 查看
举个例子

int detection_tracking(ImageBuffer* buffer,unsigned char* input_img,unsigned char* input_img_sampled,int *first_time);

{

if(*first_time)

{

//做些什么事情

*first_time=0;

}

else

{}

}

使用时

main()

{

static int first_time=1;

...

detection_tracking(buffer, input_img,input_img_sampled,&first_time);

...

}

如果函数定义为

int detection_tracking(ImageBuffer* buffer,unsigned char* input_img,unsigned char* input_img_sampled,int first_time);

则调用时,first_time的值没法被改变。因为传递的是变量的值,而不是指针地址。

另外一种方法是用return返回。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐