- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 void main and int main in C/C++
45 Lectures 4.5 hours
66 Lectures 5.5 hours
Sometimes we use int main(), or sometimes void main(). Now the question comes into our mind, that what are the differences between these two.
The main() function is like other functions. It also takes arguments, and returns some value. One point we have to keep in mind that the program starts executing from this main() function. So the operating system calls this function. When some value is returned from main(), it is returned to operating system.
The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main(). But if we want to terminate the program using exit() method, then we have to return some integer values (zero or non-zero). In that situation, the void main() will not work. So it is good practice to use int main() over the void main().
- Differentiate between int main and int main(void) function in C
- Difference between “int main()” and “int main(void)” in C/C++?
- C/C++ difference's between "int main()" and "int main(void)"
- Can we change the order of public static void main() to static public void main() in Java?
- What is the main difference between int.Parse() and Convert.ToInt32 in C#?
- What should main() return in C and 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++?
- Difference Between int and long
- Valid variant of Main() in C#
- Can main() be overloaded in C++?