Function definition inside another function definition: is it valid?

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

see this code

#include

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


        
5条回答
  •  萌比男神i
    2020-12-17 01:57

    Yes we can define a function in other function. I have compiled below written lines in gcc and it ran successfully without showing an error.

    #include;
    void main()
    {
        int sum()
        {
            int a=30, b=10, c=20, sum=0;
            sum=a+b+c;
            return sum;
        }
        int a;
        a=sum();
        printf("Sum = %d", a);
    }
    

    O/p:60

提交回复
热议问题