ex2-8-4.cpp

来自「一些学习c++的例题」· C++ 代码 · 共 27 行

CPP
27
字号
#include <iostream>

using namespace std;

void swap(int& a, int& b);

void main(void)
{
   int i = 9, j = 99;

   cout << "Demonstration: call by reference" << endl;

   cout << "Before swapped, i=" << i << ", j=" << j << endl;
   swap(i, j);
   cout << "After swapped, i=" << i << ", j=" << j << endl;
}

void swap(int& a, int& b)
{
   int t = a;

   cout << "\tSwapping, before swapped, a=" << a << ", b=" << b << endl;
   a = b;
   b = t;
   cout << "\tSwapping, after swapped, a=" << a << ", b=" << b << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?