problem with functions
I can run the following program
It does not have a function prototype but it works
printf("enter number \n");
int we(int a)
But I applied the same concept in using arrays accessing a function which takes a float as an input and produces a float as an out put it is as follows
But this program compiles but does not calculate the value
#define p 3.14
printf("summary of results\n");
printf("rad = %f area = %f\n",rad[i],area[i]);
float process(float r2)
because when I checked inside PROCESS the r2ís value=0
can anybody help me please?
Thanks in advance
There's almost no reason at all not to use prototypes. They've been standard since 1989. Using prototypes (properly) will fix your problems, as I assume you know.
At any rate, if you don't use a prototype, the compiler will assume your function looks like:
The int of course means it returns an int. The () means the arguments are unspecified. One side-effect of this is that arguments are subject to the default argument promotions. The upshot in this case is that floats are promoted to doubles. Your function (whose definition contains a prototype) says it expects a float as an argument, but that's not possible. Any float, due to the lack of a prototype at the time of the function call, will be passed as a double.
The same problem rears its head in the return value, too: the compiler thinks your function returns an int, but it doesn't. That's a problem. Even in the K&R days you needed to declare functions that returned something other than int, and today you should not only declare, but prototype. The reason your first example worked is because it returned an int (which the compiler assumed) and it was passed an int (which isn't promoted in the absence of a prototype: an int stays an int).
To make a long story short: Use prototypes. List prototypes before you call functions. Be happy.