C++ primer plus(第六版)编程练习答案 第8章 函数探幽

一、程序清单

inline.cpp

// inline.cpp -- using an inline function
#include <iostream>

// an inline function definition
inline double square(double x) { return x * x; }
int main()
{
	using namespace std;
	double a, b;
	double c = 13.0;

	a = square(5.0);
	b = square(4.5 + 7.5);   // can pass expressions
	cout << "a = " << a << ", b = " << b << "\n";
	cout << "c = " << c;
	cout << ", c squared = " << square(c++) << "\n";
	cout << "Now c = " << c << "\n";
	// cin.get();
	return 0;
}

执行结果:

a = 25, b = 144
c = 13, c squared = 169
Now c = 14

 firstref.cpp

// firstref.cpp -- defining and using a reference
#include <iostream>
int main()
{
    using namespace std;
    int rats 

猜你喜欢

转载自blog.csdn.net/qq_43445867/article/details/129781374
今日推荐