[C++] c++ 返回值和指针 →→→→→进入此内容的聊天室

来自 , 2020-04-09, 写在 C++, 查看 122 次.
URL http://www.code666.cn/view/d757719e
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. short Factor(int n, int* pSquared, int* pCubed);
  5.  
  6. int main() {
  7.         int number, squared, cubed;
  8.         short error;
  9.  
  10.         cout << "Enter a number (0 - 20): ";
  11.         cin >> number;
  12.  
  13.         error = Factor(number, &squared, &cubed);
  14.  
  15.         if (!error) {
  16.                 cout << "number: " << number << endl;
  17.                 cout << "square: " << squared << endl;
  18.                 cout << "cubed: " << cubed << endl;
  19.         } else
  20.                 cout << "Error encountered!!" << endl;
  21.         return 0;
  22. }
  23.  
  24. short Factor(int n, int *pSquared, int *pCubed) {
  25.         short Value = 0;
  26.         if (n > 20)
  27.                 Value = 1;
  28.         else {
  29.                 *pSquared = n * n;
  30.                 *pCubed = n * n * n;
  31.                 Value = 0;
  32.         }
  33.         return Value;
  34. }
  35.  

回复 "c++ 返回值和指针"

这儿你可以回复上面这条便签

captcha