Avatar ·

What should the main() function return in C++? Correct return values

Hello, colleagues! I just started learning C++ and I have a fundamental question about the `main()` function. In different code examples, I see that `main()` is declared with type `int`, but sometimes I encounter `void main()` or even just `main()` without a type. I'm completely confused. Here are a few examples I've come across: ```cpp // Example 1 void main() { // ... } // Example 2 main() { // ... } // Example 3 int main() { // ... return 0; } // Example 4 int main() { // ... return 1; } ``` My compiler (Visual Studio 2019) complains about `void main()`, but I've seen it used in some old books. And what about `return`? I read somewhere that `return 0` means successful completion, and `return 1` means an error. But what if I don't return