C语言的入门问题,谢谢~
#include <stdio.h>
int power(int m, int n);
/* test power function */
main()
{
int i;
for (i = 0; i < 10; ++i)
printf("%d %d %d\n", i, power(2,i), power(-3,i));
return 0;
}
/* power: raise base to n-th power; n >= 0 */
int power(int base, int n)
{
int i, p;
p = 1;
for (i = 1; i <= n; ++i)
p = p * base;
return p;
}
以上的程序我觉得有点问题,base没初始化,p = p * base句中函数怎么确定base值,它和i又没关联,请详细解答
参考答案:base是power()函数的参数,在调用函数时就已经将base赋值了
printf("%d %d %d\n", i, power(2,i), power(-3,i));
int power(int base, int n)
base先被赋值2,后被赋值-3