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

后端 未结 7 2150
走了就别回头了
走了就别回头了 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:18

    The default return value from a function is int. In other words, unless explicitly specified the default return value by compiler would be integer value from function.

    So, the ommiting of return statement is allowed, but undefined value will be returned, if you try to use it.

提交回复
热议问题