program_11_1.cpp
来自「清华关于C++ 的程序讲义 值得一看 关于算法」· C++ 代码 · 共 26 行
CPP
26 行
// Program 11.1: Swapping objects using indirection
#include <iostream>
using namespace std;
void IndirectSwap(char *Ptr1, char *Ptr2) {
// swap the contents of the char objects to which
// Ptr1 and Ptr2 point
char c = *Ptr1;
*Ptr1 = *Ptr2;
*Ptr2 = c;
}
int main() {
char a = 'y';
char b = 'n';
char *pa, *pb;
pa = &a; pb = &b;
// pass the lvalues of a and b to IndirectSwap()
IndirectSwap(pa, pb);
// display the new values of a and b
cout << a << " " << b << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?