I personally clearly prefer the version with (void)
, because it is usually better to declare functions with a prototype. But the form int main() { ... }
is correct, too, as long as you use it in a definition and not a declaration, and in fact the C standard uses this form in a number of examples.
Here this defines and declares a function with no prototype, but for a definition it is clear that that function doesn't receive any arguments.
If you are trying to give a forward declaration of main
, you shouldn't use that form, because there would be no warning if you called the function incorrectly. Here C and C++ are also different since C allows you to call main
yourself, even recursively, where C++ forbids such things.