C function defined as int but having no return statement in the body still compiles

后端 未结 7 2149
走了就别回头了
走了就别回头了 2020-11-28 13:48

Say you have a C code like this:

#include 

int main(){
    printf("Hello, world!\\n");
    printf("%d\\n", f());    
}

in         


        
7条回答
  •  迷失自我
    2020-11-28 14:00

    The return value in this case, depending on the exact platform, will likely be whatever random value happened to be left in the return register (e.g. EAX on x86) at the assembly level. Not explicitly returning a value is allowed, but gives an undefined value.

    In this case, the 14 is the return value from printf.

提交回复
热议问题