Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

why does the execution of a c++ program start with main()???

Answer Posted / rajesh paul

Actually this is a very obvious question from our curiosity...
Even I was also very much puzzled at one time with this question and after a long time of discussion with my frnds and some books I got it clear. The explanation is as follows--




consider the code segment given by Brian--


class MyStatic
{
public:
MyStatic() { cout << "MyStatic Class called." << endl; };
};

static MyStatic ms;

void main()
{
cout << "main called." << endl;
}

Output : =
MyStatic Class called.
main called.
---------------X---------------

This happens because at run-time the static members are loaded into the RAM automatically along with the main() function. Hence as the class 'MyStatic' is statically instantiated before main(), the constructor function is called before main() as because the object is static i.e. already loaded into RAM hence the constructor is executed. Thereafter the main() is executed.


So from this discussion we come to the conclusion that "It is OS that instructs the system loader to load the main() into RAM automatically at run-time but no other function is loaded into RAM until and unless the main() calls them". That's what I want to say...........................

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define stl.

1276


How is stl different from c++ standard library?

1338


please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html

2274


Why should a c++ programmer be interested in stl?

1102


Can we use stl in coding interviews?

1828


What is a list in c++ stl?

1172


When did c++ add stl?

1241


How does an stl file work?

1172


What are the various types of stl containers?

1192


How connect plc and pc through software

2495


What is stl stack?

1140


Is stl part of c++ standard?

1102


Describe the My Computer and My Documents folders; identify the elements that are present in every Window.

2543


What are the components of stl?

1114


Is string part of stl?

1217