+ 1

Why can't we use void main instead of int main and return nothing.

14th Dec 2016, 6:17 PM
Rohin Bardhan
3 Réponses
+ 1
you can also use void main instead of int main. it is completely depends upon you what's you want to use. if you don't have any need to return anything from main function than you can use void main also. but mostly you will see main function is written as a int main() and it's will return something 0 or 1. so may be it's just a way for standard programming so everyone follows it. but personally i always use void main().
14th Dec 2016, 6:24 PM
Darshan Dhoriya
Darshan Dhoriya - avatar
+ 1
C++ recognizes the int main() and runs the code inside when the program is run. If you make a void main() instead of an int main() it will not recognizes it as a main function and will not run it when the code starts! You also ways need the main to be of type int!!!
14th Dec 2016, 9:05 PM
John K
John K - avatar
0
You can use void main in case you don't need to return something from main , in case the code won't run type : system("pause") before you close main
15th Dec 2016, 4:56 PM
Daniel Saade