Ç - 指针时新的函数调用 [英] C - pointers when new functions are called

查看:81
本文介绍了Ç - 指针时新的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这样的:

function2(int *hello) {
    //something
}

function1(int *hello) {
    function2(&hello);
}

void main() {
    int hello = 0;
    function1(&hello);
}

我如何让这个函数2 可以更改声明的初始值主

推荐答案

更改此code:

function1(int *hello) {
   function2(&hello);
}

function1(int *hello) {
   function2(hello);  // <-- no "&" in this call!
}

然后,你可以这样做:

Then you can do this:

function2(int *hello) {
    *hello = 123;     // <-- dereference pointer hello
}

这篇关于Ç - 指针时新的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆