- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between “int main()” and “int main(void)” in C/C++?
Sometimes we see that there are two types of main function definition. The int main() and int main(void). So is there any difference?
In C++, there is no difference. In C also both are correct. But the second one is technically better. It specifies that the function is not taking any argument. In C if some function is not specified with the arguments, then it can be called using no argument, or any number of arguments. Please check these two codes. (Remember these are in C not C++)
Example
#include<stdio.h> void my_function() { //some task } main(void) { my_function(10, "Hello", "World"); }
Output
This program will be compiled successfully
Example
#include<stdio.h> void my_function(void) { //some task } main(void) { my_function(10, "Hello", "World"); }
Output
[Error] too many arguments to function 'my_function'
In C++, both the program will fail. So from this we can understand that int main() can be called with any number of arguments in C. But int main(void) will not allow any arguments.
- Related Articles
- C/C++ difference's between "int main()" and "int main(void)"
- Difference between void main and int main in C/C++
- Differentiate between int main and int main(void) function in C
- Difference between const int*, const int * const, and int const * in C/C++?
- Difference between const int*, const int * const, and int const * in C
- What is difference between int and const int& in C/C++?
- What is the difference between const int*, const int * const, and int const *?
- What is the difference between size_t and int in C++?
- What is the difference between int and Int32 in C#?
- Difference Between int and long
- What is the main difference between int.Parse() and Convert.ToInt32 in C#?
- Can we change the order of public static void main() to static public void main() in Java?
- What is the difference between an int and a long in C++?
- Difference between an Integer and int in Java
- Difference between MySQL BigInt(20) and Int(20)?

Advertisements