求助c语言的一个问题?

被调函数在主函数后 那在主函数中怎么声明被调函数额
2025-02-24 08:46:58
推荐回答(3个)
回答1:

在调用的前一行复制粘贴函数头,然后加个分号。

回答2:

比如函数体为
int pow(int a,int b)
{
}
那么在主函数体中添加为
int pow(int a,int b);

回答3:

分两种情况
1 在同一个文件中
你只需要在main函数定义之前声明你的函数原型(prototype)就行,例如
int myfun(void);
/*declaration of a local function's prototype*/
int main(){
/*suite of main*/
return myfun();
}
int myfun(void){
/*suite of function myfun*/
return 0;
第二种情况是不在同一个文件之中
这时
int myfun(void);
就应该被换成
extern int myfun(void);
/*例如 gcc main.c myfun.c -omain.exe*/
就是这么简单,当然还有通过指定编译器选项的办法,这个可以在一些大型项目里见到,不具体列出