Two 'main' functions in C/C++

后端 未结 16 1427
一整个雨季
一整个雨季 2020-12-01 16:08

Can I write a program in C or in C++ with two main functions?

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 16:34

    What do you mean by "main function"? If you mean the first function to execute when the program starts, then you can have only one. (You can only have one first!)

    If you want to have your application do different things on start up, you can write a main function which reads the command line (for example) and then decides which other function to call.

提交回复
热议问题