如何保持存储在作为参数传递的指针中的地址在所有函数调用中保持一致

问题描述 投票:1回答:1

我可以通过引用传递任何参数,并且在任何函数调用中对该变量的更改也将反映在其他函数调用中。

同样,如果我想使存储在指针中的地址在所有函数调用中保持一致,以使其表现得像我们通过引用传递指针一样。

c++ function c++11 pointers parameter-passing
1个回答
1
投票
#include <iostream> void f(int * & p) { std::cout << p << std::endl; } int main() { int x; int * p = &x; std::cout << p << std::endl; // This prints the same... f(p); // ... as this. }
© www.soinside.com 2019 - 2024. All rights reserved.