Difference between void main and int main?


Question

Does it matter which way I declare my C++ programs?

1
53
3/12/2009 12:01:30 PM

Accepted Answer

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

And yes, it does matter. Either

int main(int argc, char** argv)

or

int main()

are 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 older Microsoft's C++ compilers.

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

69
8/12/2018 6:10:02 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon