Where should we use void main() and where should we use int main()?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Where should we use void main() and where should we use int main()??

1st Dec 2016, 1:13 PM
aman
6 Answers
+ 1
use int main when there's chance of an error. If you're doing something that might produce errors (such as opening files, dereferencing pointers etc.) use int main so that by the return status you can tell if any error occurred or not
3rd Dec 2016, 6:34 AM
Aniket Bhattacharyea
Aniket Bhattacharyea - avatar
0
Use void main() if your function does not output anything and use int main() if your function outputs anything.
1st Dec 2016, 2:17 PM
Twaha Rahman
Twaha Rahman - avatar
0
doesn't matter if you use void main() .. void means empty... which means function will not return any value...but of you write int main() you have to write return 0; else you will get an error function should return a value..
2nd Dec 2016, 3:00 AM
Rahul Sharma
Rahul Sharma - avatar
0
1. void main() returns null(no return keyword required) 2. int main() requires return value(even if you have not used it in the code, compiler automatically adds it) the return value is 0 for success and non-zero for errors .Hope this helps.
4th Dec 2016, 3:10 PM
K Mahesh Kumar Sharma
0
depends on the version you use. If you are using a newer version like the dev C++, keep using int main(). manuals say that it returns a value to OS. Not sure what that does, but programs don't run in dev c++ without int main in dev c++
7th Dec 2016, 8:34 PM
Tapaj
0
Can you guys give me an example? Is It like : int main wait(300);?
4th Jan 2017, 8:56 AM
Jere