What happens if you don't return a value in C++?

后端 未结 6 785
南方客
南方客 2020-12-28 18:56

Yesterday, I found myself writing code like this:

SomeStruct getSomeStruct()
{
    SomeStruct input;

    cin >> input.x;
    cin >> input.y;
}
<         


        
6条回答
  •  -上瘾入骨i
    2020-12-28 19:28

    You didn't get any warning because you didn't have -Wall -Werror turned on. (As stated in other answers)

    However I think you probably got a zero-filled struct as the result because the stack object was default constructed in the caller function, possibly with explicit zero arguments, or else due to zeros on the stack?

提交回复
热议问题