I have noticed everyone using "int main(void)".But doesnt the
standard pronounces it as
"int main(int argc,char *argv[])".And if i don't specify arguments,why
can't i simply put it as "int main()"
In C, "int main()" declares main as a function taking an unspecified
number and type of arguments. This goes back to the old-style
function declarations that existed before prototypes were introduced;
old-style declarations are still legal.
<OT>
In C++, "int main()" means specifically that main takes no arguments.
This is simpler and more consistent, and it's possible because C++
doesn't support old-style function declarations. C's use of the "void"
keyword here is necessary for backward compatibility.
</OT>
It's been said that the main function is unique because it can be
defined in more than one way. In fact, it's unique because the
language *restricts* the ways it can be defined. If you want to have
a function "foo", you can define it any way you like. The "main"
function is different because, unlike "foo", it's called by the
external environment; the language imposes restrictions on how you can
define it so that the environment can figure out how to call it
properly. It would have been simpler to restrict it even further,
allowing only one form for main, but it was decided that the extra
flexibility (for programs that don't use command line arguments) was
worth the slight extra burden on the implementation.