0

Can we declare main as void and not use return statement

14th Nov 2016, 11:00 AM
Shreyash Mundhra
Shreyash Mundhra - avatar
6 Answers
+ 2
C++ does not support void Main(). If you want to use void just use like this. public int Main() { main_void(); return 0; } public void main_void() { // here goes the code }
14th Nov 2016, 11:28 AM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar
+ 1
"The definition void main() is not and never has been used in C++." by creator of c++ when you use void main instead of int. It will throw an error. that main should be int.
14th Nov 2016, 11:12 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
You can omit the "return 0;" inside the main function, but it needs to be int.
14th Nov 2016, 12:07 PM
Schindlabua
Schindlabua - avatar
+ 1
In my experience, you can use void and it will still operate correctly. But, using int gives you an advantage; you can use return 0 to terminate the program whenever you want.
14th Nov 2016, 12:23 PM
Keto Z
Keto Z - avatar
0
lets assume void main() works in c but not in c++.
14th Nov 2016, 11:42 AM
Franky BrainBox
Franky BrainBox - avatar
0
no because void main is start of program
14th Nov 2016, 12:12 PM
rahul singh
rahul singh - avatar