Return type float from function in c

I have this simple code:

int main()
{
    float x = foo();
    printf("returned value: %f", x);
    return 0;
}

float foo ()
{
    return 5;
}

when I run the code, the output is: "return value: -858993472.000000"

Can someone please explain to me why the return value is not 5.000000?

+5
source share
1 answer

The moment you call the function, there is no prototype in the area. This means that the function is supposed to return int. Add a prototype until you call the function first.

float f(void);
+18
source

All Articles