+ 1

[DUPLICATE] What is the difference between void main() and int main()

How void main() and int main() works.

29th Mar 2018, 7:10 PM
Richard Job B
Richard Job B - avatar
2 Answers
+ 2
main is a fuction... a function may return something... eg..a char..a int...a float...an array...another function...etc void main()...suggests main() wont return anything inn main suggests...it will return a integer value... thats why we write return 0 at the end... for main...in general u can use any between int and void...
29th Mar 2018, 7:35 PM
sayan chandra
sayan chandra - avatar
+ 2
We return 0 when the programs ends like it should. We return -1 when it ends unexpectedly because of an exception. Those are conventions. We can actually return whatever integer we want. We can define our own error codes when a program ends. If we have a huge program (parent process) with multiple child processes, we can let a child process do a specific calculation and collect its return value like it's a normal function in the parent class. While learning C++, the return value of the main function usually doesn't matter a lot. Still, using int main() and returning 0 (in most compilers you don't even have to write this line) is good practice.
29th Mar 2018, 9:48 PM
Chris
Chris - avatar