Saturday, September 13, 2014

How many main functions we can write in single program of C /C++ ?

We can write two main functions in a single program.but we should write one main function as main function and other main function as calling function  in that main function....as shown in below

#include<stdio.h>
void main()
{
    printf("hello im going to enter into second main\n ");
    main();
   printf("im still waiting for execution...\n");
}


from the above program first execution start from the first main ,then it will execute and prints the massage
"hello im going to enter into second main"
hello im going to enter into second main
hello im going to enter into second main
hello im going to enter into second main
hello im going to enter into second main
hello im going to enter into second main
hello im going to enter into second main
..................................

it will never print the massage  "im still waiting for execution..."   because it will execute and repeats the first printf only because main calls main only..............