C函数 [英] Functions in C
本文介绍了C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个计算数字幂的程序
示例2 ^ 5 = 32
程序
I wrote a program which calculte the power of a number
example 2^5 = 32
program
#include<stdio.h>
#include<conio.h>
void main(){
int a,b,c;
int power();
printf("base value : ");
scanf("%d",&a);
printf("power value : ");
scanf("%d",&b);
c=power(a,b);
printf("value of a power b =%d",c);
getch();
}
当我编译该程序时出现错误
第12行出错:调用power()的附加参数
但是在此程序中不会出现错误
程序
when i compile this program an error comes
Error at line 12 : Extra Parameter to call power()
But in this program no error comes
Program
int power(int x,int y){
int k,l,m=1;
k=x;l=y;
for(int i=0;i<l;i++)
m = m*k;
return(m);
}
void main(){
int a,b,c;
printf("base value : ");
scanf("%d",&a);
printf("power value : ");
scanf("%d",&b);
c=power(a,b);
printf("value of a power b =%d",c);
getch();
}
我认为第一个程序的函数声明存在问题.
但是根据书的功能可以在不指定参数的情况下进行声明.所以我声明为"int power();"
请说明错误是什么意思,问题出在哪里.
I think there is a problem in function declaration in 1st program.
but according to book function can be declared without specifying arguments. So i declared as "int power();"
Please tell what error means and where is the problem.
推荐答案
如果您查看两个程序之间的差异,为什么会注意到?我注意到了:
int power();
错误消息有点怪异,但我认为这完全令人困惑,因为您的语法没有意义.试试
整数功率;
或者只是摆脱那条线,我没有注意到它有任何作用.
power方法是否存在于第一个程序中,而您没有显示它?
IF you look at the differences between the two programs, why do you notice ? I notice this:
int power();
The error message is a bit weird, but I think it''s totally confused because your syntax makes no sense. Try
int power;
Or just get rid of that line, I''m not noticing that it does anything.
Does the power method exist in the first program and you just didn''t show it ?
这篇关于C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文