Can anyone tell me the difference between int main()
and int main(void)
? Why do both of them work and what is the default argument to int main()
?
No difference under ordinary circumstances. This is no 'default argument to main()', since it has no arguments at all.
Here's the un-ordinary circumstance. If you write your own call to main, then ()
will permit you to pass it any parameters you like, while (void)
will force you to pass it none. Still, none of this matters in terms of the 99.99999999% case, which is main being invoked by the runtime to launch your program. The runtime neither knows nor cares if you write ()
or (void)
.
If you code the standard int main(int argc, char **argv)
you will get your command-line parameters in there.