The compiler throws this warning because you did not declare the function return type in the function declaration
The syntax for function declaration
return-type function-name(parameters)
{
some statements
}
When you don’t declare the return type of a function in the function declaration
if the compiler that you are using is C89 then, in that case, it will assume the return type of a function as an int
At the same time, if the compiler that you are using is C99 then, in that case, it will be illegal and will produce an error
To clarify, Consider the below example as can be seen, in the function declaration the return type is not declared
calsum(int x, int y, int z) //function declaration
In C89 your code will be compiled by assuming it is an int while, on the other hand, in C99 it will be illegal and can create an error
#include <stdio.h>
#include <stdlib.h>
int calsum(int x, int y, int z);
int main()
{
int a,b,c,sum;
printf("enter any three numbers");
scanf("%d%d%d",&a,&b,&c);
sum=calsum(a,b,c); // function call
printf("sum=%d\n",sum);
return 0;
}
calsum(int x, int y, int z) //function declaration
{
int d;
d=x+y+z;
return(d);
}
Leave a Reply