1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

calling function

Discussion in 'C++' started by buddy, Aug 31, 2007.

  1. buddy

    buddy New Member

    Joined:
    Aug 31, 2007
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    can a function be called without calling main( ) function??? please calrify me.. if so plz explain it in detail.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    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;
    }
    
     

Share This Page