Why there is no compiler error when return statement is not present?

前端 未结 7 1275
自闭症患者
自闭症患者 2021-01-08 00:19

Unlike Java, in C/C++ following is allowed:

int* foo ()
{
  if(x)
    return p;
// what if control reaches here
}

This oft

相关标签:
7条回答
  • 2021-01-08 01:00

    AFAIR Visual Studio 2008 warns you about "execution path that does not have return value". It is allowed in the meaning of that "C++ won't stop you from shooting you in the foot". So you are to think, not the compiler.

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