0
How to add without using main function in c++
3 odpowiedzi
+ 2
Your program must have a main function. It is the function that is executed when launching your program.
+ 1
As @Zen said definitely we need the main() method to execute our program.
But still you can do the addition of two numbers before main gets called. Like this,
class test
{
test ()
{
cout << 4 + 5 << endl;
}
};
test obj;
int main ()
{
cout << "Inside Main";
return 0;
}
OUTPUT for this is :
9
Inside Main
obj gets create before main gets called because global object will be created or initialize before main gets called.
Hope this is what you are looking for and I guess it's helpful to you.
0
create a seperate function with a return value