+ 5
Why do we use int main()? Y not void main()?
3 Answers
+ 8
void main() is obsolete and no longer supported by modern compilers. In the latest standard, main() must return int.
+ 2
That's because main returns 0 by default at the end of the function.
We can manually type "return 0;" at the end of the function if we want, because it's basically the same thing.
+ 1
the return int value gives clue to the calling process about the way the program ended.
A program that returns a 0 value successfully terminated when other values stand for different error cases.
You can then use this return value in, for example, bash scripts to test if your program execution succeeds.
For this reason the C++ standard defined the main function with an integer as return value.
void main() may work with some compilers but has never been valid.