I was trying to build a very simple program in C that returns a float value from a function, but for some reason I got an error.
#include<stdio.h>
int main(){
double returning;
returning = regre();
printf("%f", returning);
return 0;
}
double regre(){
double re = 14.35;
return re;
}
The error am getting says:
conflicting types for 'regre'
previous implicit declaration of regre was here
That error message is telling you exactly what's happening - there is an implicit declaration of regre
because you don't define it until after main()
. Just add a forward declaration:
double regre();
Before main()
, or just move the whole function up there.
previous implicit declaration of `regre` was here
If a function is unknown, then compiler considers it as int functionname()
by default. In your case int regre()
will be declared here.
conflicting types for 'regre'
When your actual function double regre()
is noticed, this conflict error occurs. To solve this issue, double regre() function should be declared before it's actual use.
#include<stdio.h>
double regre(); //Forward Declaration
int main(){
double returning;
returning = regre();
printf("%f", returning);
return 0;
}
double regre(){
double re = 14.35;
return re;
}
For more info on Forward Declaration, refer the following link.
http://en.wikipedia.org/wiki/Forward_declaration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With