What's the return value from a function call if that function doesn't really provide one

后端 未结 1 1848
半阙折子戏
半阙折子戏 2020-12-04 01:15

Let\'s say we have following code:

int func(char str[], int len) {
    // Don\'t return anything here.
}

int main() {
    char str[] = \"Hello\";
    int re         


        
相关标签:
1条回答
  • 2020-12-04 01:52

    If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. In this case, the return value of the called function is undefined. If a return value is not required, declare the function to have void return type; otherwise, the default return type is int.

    As mentioned above its undefined so finding root cause behind some random value as return will be useless.

    0 讨论(0)
提交回复
热议问题