先给个例子,这个函数的功能是计算x^n,并返回结果,n>=0double是返回值的类型,传入的参数双精度型x是底数,整型n是指数double power(double x, int n) // Function header{ // Function body starts here...
double result = 1.0; // Result stored here
for(int i = 1; i <= n; i++)
result *= x;
return result;} // ...and ends here在main()函数中调用到这个函数时,可以这样写:int result = power(x, n);我发一本书给你吧,是visual c++ 2008入门经典,里面有很多浅显经典的例子,你可以尝试在c++环境里面运行一下,就会有更形象的理解了~~