W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
#include <iostream>
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 << "交换前: " << "\n";
  cout << firstNum << secondNum << "\n";
​
  swapNums(firstNum, secondNum);
​
  cout << "交换后: " << "\n";
  cout << firstNum << secondNum << "\n";
​
  return 0;
}