Function definition inside another function definition: is it valid?

后端 未结 5 1322
广开言路
广开言路 2020-12-17 01:05

see this code

#include

int main()
{
    void test(void)
    {
        printf(\"test\");
        return;
    }
printf(\"main\");
return 0;
}
<         


        
5条回答
  •  無奈伤痛
    2020-12-17 01:54

    Defining a nested function (i.e. inside another function) is valid, the only limitation is that the former function's scope is limited by the enclosing function. It's just like defining a local variable. You can find more information here: http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

提交回复
热议问题