From a practical viewpoint, there's no real difference. With int main(void)
, you're explicitly stating that main
takes no parameters, so you can't invoke it with any. With int main()
, you're leaving open the possibility of invoking main
with some parameters.
However, except in strange situations like code golf or intentionally obfuscated code, you don't invoke main
anyway -- it's the entry point to the program, so it's automatically invoked by the startup code. The startup code will pass the command line arguments anyway, so your choices don't change how it's invoked, only whether you use or ignore the parameters that get passed.
The standard does specifically allow you to define main
with or without parameters (§5.1.2.2.1/1):
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;
Though it's outside the tags specified, in C++ the situation is slightly different. In C, a function declaration like:
int f();
specifies that f
is a function returning an int
, but gives no information about the number or type of parameters f
might expect (this is included primarily for compatibility with old code -- at one time, this was the only way to declare a function in C). In C++, that same declaration explicitly declares f
as a function that takes no parameters, so attempting to invoke f
with one or more parameters cannot invoke this function (it must either invoke another overload or produce an error if no suitable overload is found).