Let us consider the following program:
#include<stdio.h>
int test(a,b,c)
{
return a+b+c;
}
int main()
{
printf("%d\n",test(1,2,3));
printf("%d\n",test(1.5,2.2,2.3));
}
I didn't know that it is possible to specify functions in C without defining the types of its parameters. This is a feature of ANSI C? Can someone explain this to me?
I thought it was not possible to do that. However, my compiler can compile this program! In which situations I can do that?
Also, The program behaviour is a little weird. When I use integer values, the function does what we expect. However, when I use float parameters, the result is very different from what I would expect.
double; you'd have to write1.5Fto make them of typefloat. When there's no prototype for a function, as there isn't withtest(), then all parameters undergo default promotions — integer types shorter thanintare converted toint, andfloatvalues are converted todouble. Using K&R-style function definitions these days is an extremely bad idea, but they are still allowed by the C11 standard. You should never write one yourself; you should aim to upgrade any you find in the code you work on.