gpt4 book ai didi

c++ - 在 C++ 中通过引用传递的两种方式?

转载 作者:搜寻专家 更新时间:2023-10-31 00:19:00 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate: What are the differences between pointer variable and reference variable in C++? How to pass objects to functions in C++?

我正在学习引用参数并得到以下问题:

这有什么区别:

void B(int* worthRef) {
*worthRef += 1;
}

int main() {
int netWorth = 55;
B(&netWorth);
return 0;
}

还有这个:

void B(int &worthRef) {
worthRef += 1;
}

int main() {
int netWorth = 55;
B(netWorth);
return 0;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com