How can a program with a global variable called main instead of a main function work?

前端 未结 7 1487
长情又很酷
长情又很酷 2020-12-07 12:05

Consider following program:

#include 
int main = ( std::cout << \"C++ is excellent!\\n\", 195 ); 

Using g++ 4.8.1 (mi

7条回答
  •  庸人自扰
    2020-12-07 12:47

    You are doing tricky work here. As main( somehow) could declared to be integer. You used list operator to print message & then assign 195 to it. As said by someone below, that it doesn't comfort with C++, is true. But as compiler didn't find any user defined name, main, it didn't complaint. Remember main is not system defined function, its user defined function & thing from which program starts executing is Main Module, not main(), specifically. Again main() is called by startup function which is executed by loader intentionally. Then all of your variables are initialized, & while initializing it output like that. That's it. Program without main() is ok, but not standard.

提交回复
热议问题