相关疑难解决方法(0)

C++返回值没有return语句

当我运行这个程序时:

#include <iostream>

int sqr(int&);

int main()
{
    int a=5;
    std::cout<<"Square of (5) is: "<< sqr(a) <<std::endl;
    std::cout<<"After pass, (a) is: "<< a <<std::endl;
    return 0;
}

int sqr(int &x)
{
    x= x*x;
}
Run Code Online (Sandbox Code Playgroud)

我得到以下输出:

Square of (5) is: 2280716
After pass, (a) is: 25
Run Code Online (Sandbox Code Playgroud)

什么是2280716?而且,如果函数中sqr(a)没有return语句,我如何获得返回的值int sqr(int &x)

谢谢.

c++ return-value

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

return-value ×1