Difference between void main and int main?

This question already has an answer here:

  • What should main() return in C and C++? 19 answers

  • The difference is one is the correct way to define main , and the other is not.

    And yes, it does matter.

    int main(int argc, char** argv)
    

    or

    int main()
    

    is the proper definition of your main per the C++ spec.

    void main(int argc, char** argv)

    is not and was, IIRC, a perversity that came with Microsoft's C++ compiler.

    https://isocpp.org/wiki/faq/newbie#main-returns-int


    Bjarne Stroustrup made this quite clear:

    The definition void main() is not and never has been C++, nor has it even been C.

    See reference.


    You should use int main . Both the C and C++ standards specify that main should return a value.

    链接地址: http://www.djcxy.com/p/28714.html

    上一篇: C ++中main的签名参数是否具有unsiged和const限定符?

    下一篇: void main和int main之间的区别?