Friday, 5 July 2013

Nesting of Functions in C

  In many C text books you might see the following piece of information "C language does not allow nesting of functions". But this information is not entirely true. At least for GCC you can have nesting of functions in C. The following program compiles fine with GCC.

#include<stdio.h>
int main()
{
 void first()
 {
     printf("\nFirst Level of Nesting\n");
     void second()
     {
         printf("\nSecond Level of Nesting\n");
         void third()
         {
             printf("\nThird Level of Nesting\n");
         }
         third();
     }
     second();
 }
 first();
}

 

The Figure Below Shows the Output

  Click here to download the C Program.