📄 hour11_2.cpp
字号:
//Listing 11.7
// Returning multiple values from a function by using references instead of pointers
#include <iostream>
short Factor(int, int &, int &); // note the & instead of the * in the original code
int main()
{
int number, squared, cubed;
short error;
std::cout << "Enter a number (0 - 20): ";
std::cin >> number;
error = Factor(number, squared, cubed);
if (!error)
{
std::cout << "number: " << number << "\n";
std::cout << "square: " << squared << "\n";
std::cout << "cubed: " << cubed << "\n";
}
else
std::cout << "Error encountered!!\n";
return 0;
}
short Factor(int n, int &pSquared, int &pCubed) // note the & instead of the * in the original code
{
short Value = 0;
if (n > 20)
Value = 1;
else
{
pSquared = n*n; // this line also changed -- no dereference *
pCubed = n*n*n; // this line also changed -- no dereference *
Value = 0;
}
return Value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -