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
C Introduction
C Features
C Installation
C Basic Program Structure
C Comments
Features of C Language
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is C language?
What are the main features of C language?
What is the basic structure of a C program?
What is the difference between a compiler and an interpreter?
What is the difference between int main() and int main(void) in C?