ex0708.cpp
来自「《C++编程习题与解答》书中所有例题与习题的源代码」· C++ 代码 · 共 21 行
CPP
21 行
// Programming with C++, Second Edition, by John R. Hubbard
// Copyright McGraw-Hill, 2000
// Example 7.8 on page 162
// Returning a reference
#include <iostream>
using namespace std;
int& max(int&,int&);
int main()
{ int m = 44, n = 22;
cout << m << ", " << n << ", " << max(m,n) << endl;
max(m,n) = 55; // changes the value of m from 44 to 55
cout << m << ", " << n << ", " << max(m,n) << endl;
}
int& max(int& m, int& n) // return type is reference to int
{ return (m > n ? m : n); // m and n are non-local references
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?