<分区>
假设我有这样的东西:
function2(int *hello) {
//something
}
function1(int *hello) {
function2(&hello);
}
void main() {
int hello = 0;
function1(&hello);
}
如何使 function2
可以更改 main
中声明的原始值?
<分区>
假设我有这样的东西:
function2(int *hello) {
//something
}
function1(int *hello) {
function2(&hello);
}
void main() {
int hello = 0;
function1(&hello);
}
如何使 function2
可以更改 main
中声明的原始值?
最佳答案
更改此代码:
function1(int *hello) {
function2(&hello);
}
到:
function1(int *hello) {
function2(hello); // <-- no "&" in this call!
}
然后你可以这样做:
function2(int *hello) {
*hello = 123; // <-- dereference pointer hello
}
关于C - 调用新函数时的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19602300/