Can we call any function before the main function is called?
Yes, if we create any object in global scope, its constructor will be called for initialization before the main function is called.
Here is an example:
#include<iostream>
using namespace std;
class myClass
{
public:
myClass ()
{
cout << "myClass" << endl;
}
};
myClass a[4];
int main ()
{
cout << "main" << endl;
return 0;
}
The above program would print "myClass" four times during the initialization of objects a[0] to a[3], and then the control would pass to the main function.