C语言解决 [Error] conflicting types for ‘函数名‘ 和 [Note] previous implicit declaration of ‘函数名‘ was here

报错原因

函数未被声明就被调用

第一种是相对于主函数

#include <stdio.h>

int main(){
	......
	F(a,b);
	......
}

float F(int a,int b){
	......
}

函数在调用前需要提前声明,或者将函数放在主函数前

  1. 提前声明
#include <stdio.h>

float F(int a,int b);

int main(){
   ......
   F(a,b);
   ......
}

float F(int a,int b){
   ......
}
  1. 函数放在主函数前
#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函数前

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值