What is difference between int main and void main? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is difference between int main and void main?

28th Nov 2016, 10:39 PM
Mufakkir
Mufakkir - avatar
4 Answers
+ 2
When we return 0 at the end ( while using int as the return type) it tells the OS that the program is functional and is without any error(except logical error), as main function is called by OS and it returns 0 to the OS. In C++, there is no difference, both are same.
29th Nov 2016, 1:06 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 2
void main means that your program returns nothing to the OS that preempted your program to run but if there are any significant non-zero errors you want to return then int main is the way to go, the OS will report the int error as an error that you should be able to them identify as coming from your program, int main is what is used in the industry for this reason
29th Nov 2016, 2:02 AM
Eric Gitangu
Eric Gitangu - avatar
+ 1
int main returns a value through "return 0;" statement when it's works done! but the void main doesn't return any value and when it's works done, after the '}' character of main, it will stop (end of application) automatically however the void main will be done when you use "return;" statement in anywhere of your main's body.
28th Nov 2016, 10:52 PM
Nima Moradi
Nima Moradi - avatar
+ 1
feedback or not. Return value is used for checking excution status of the program.
28th Nov 2016, 10:56 PM
iw.song
iw.song - avatar