Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   calling function (http://www.go4expert.com/forums/calling-function-t6138/)

buddy 31Aug2007 23:48

calling function
 
can a function be called without calling main( ) function??? please calrify me.. if so plz explain it in detail.

DaWei 1Sep2007 00:18

Re: calling function
 
No. Main is called by the executive that launches the program. One should never call main explicitly. The effects of doing so result in undefined operation.

shabbir 1Sep2007 12:09

Re: calling function
 
Quote:

Originally Posted by buddy
can a function be called without calling main( ) function??? please calrify me.. if so plz explain it in detail.

Yes a function can be called without calling the main or I would say a function can be executed before the main function is executed. Try running this program.
Code:

#include<iostream>
using namespace std;

int func()
{
        cout<<"In Func"<<endl;
        return 10;
}

static int i = func();

int main()
{
        cout<<"In Main"<<endl;
        return 0;
}



All times are GMT +5.5. The time now is 16:55.