开发者

returning a float type from function in c

开发者 https://www.devze.com 2023-02-02 09:11 出处:网络
I have this simple code: int开发者_Python百科 main() { float x = foo(); printf(\"returned value: %f\", x);

I have this simple code:

int开发者_Python百科 main()
{
    float x = foo();
    printf("returned value: %f", x);
    return 0;
}

float foo ()
{
    return 5;
}

when i run the code , the output is: "returned value: -858993472.000000"

can somebody please explaing to me why does the returned value isnt 5.000000?


At the point at which you call the function there is no prototype in scope. This means that the function is assumed to return int. Add a prototype before the point where you first call the function.

float f(void);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号