Can we have functions inside functions in C++?

后端 未结 12 2318
抹茶落季
抹茶落季 2020-11-22 14:51

I mean something like:

int main() 
{
  void a() 
  {
      // code
  }
  a();

  return 0;
}
12条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 15:22

    No, it's not allowed. Neither C nor C++ support this feature by default, however TonyK points out (in the comments) that there are extensions to the GNU C compiler that enable this behavior in C.

提交回复
热议问题