报错原因
函数未被声明就被调用
第一种是相对于主函数
#include <stdio.h>
int main(){
......
F(a,b);
......
}
float F(int a,int b){
......
}
函数在调用前需要提前声明,或者将函数放在主函数前
- 提前声明
#include <stdio.h>
float F(int a,int b);
int main(){
......
F(a,b);
......
}
float F(int a,int b){
......
}
- 函数放在主函数前
#include <stdio.h>
float F(int a,int b){
......
}
int main(){
......
F(a,b);
......
}
第二种是相对于其他函数
#include <stdio.h>
float G(int x,int y){
......
F(int a,int b);
......
}
float F(int a,int b){
......
}
int main(){
......
G(a,b);
......
}
函数G需要调用函数F,但函数F被放在了函数G后面,这也就意味着函数G调用F是F并没有被声明,那么F就会被编译器定义为隐式函数,默认为int型函数,如果存在返回值的话,返回值类型与函数类型不一致,就会导致报错,解决方法同第一种相对于主函数报错的解决方法一样,F函数提前声明于G函数前或F函数放在G函数前。

5万+

被折叠的 条评论
为什么被折叠?



