当我运行这个程序时:
#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)?
谢谢.