主页
C++
C++ 通过引用传递参数
demo_functions_ref
运行 ❯
×
更改方向
保存代码
更改主题
#include
using namespace std; void swapNums(int &x, int &y) { int z = x; x = y; y = z; } int main() { int firstNum = 10; int secondNum = 20; cout << "Before swap: " << "\n"; cout << firstNum << secondNum << "\n"; swapNums(firstNum, secondNum); cout << "After swap: " << "\n"; cout << firstNum << secondNum << "\n"; return 0; }
Before swap:
1020
After swap:
2010