【发布时间】:2020-02-08 08:02:48
【问题描述】:
具有两个间接运算符的函数参数的用途是什么?
由于引用调用正在更改原始变量的值,我认为带有两个间接运算符的函数参数可能会更改原始值的地址。
但正如我在下面的尝试所示,它没有:
void addrchanger(int**);
int main()
{
int value1 = 4;
int* value1ptr = &value1;
std::cout<<&value1<<std::endl;
addrchanger(&value1ptr);
std::cout<<&value1<<std::endl;
//the address of value1 doesn't change.
}
void addrchanger(int** foo)
{
//this is an attempt to change the address of value1 to the next slot
++**foo;
}
【问题讨论】:
-
它改变了你的价值1。使用 cout
-
您永远无法更改任何地址。一旦某个东西被创造出来,它就会一直停留在同一个地方,直到它不再存在为止。
标签: c++ function parameters