What is the difference between int main() and int main(void) in C?

In C, int main() says nothing about the parameters, so the function can be called with any arguments (in older C standards). int main(void) clearly says that it takes no parameters. So int main(void) is the better and safer form.

If you want the command line arguments, use int main(int argc, char *argv[]). See Command Line Arguments.

Note that in C++ both forms mean the same thing. Also void main() is not standard, so always use int.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.