通过指针的引用查找正方形

To find square by reference of pointers

本文关键字:查找 正方形 引用 指针      更新时间:2023-10-16
#include <iostream>
using namespace std;
void square (int *);
int main () {
    int number = 0;
    cout << " To find the square of the number entered by the user ";
    cin >> number;
    cout << square (&number);
    return 0;
}
void square (int *x) 
{
    *x = *x ** x;
}

谁能说出这段代码中的错误是什么,因为它给了我一个冗长的奇怪错误

由于square不返回值,因此它不能向cout传递任何内容

而是更改行

 cout << square (&number);

 square (&number);
 cout << number;

错误在于main()期望square() return结果,而 square 是一个就地修改其参数的void函数。

错误消息基本上是这样说的:没有operator<<需要void因为它是右手论证。