Friday 17 June 2011

What’s the difference between void main and int main?

Void main (): You can't return a value from void main. i.e., you can't return 0; at the end of main (). You can use "return;" but no value is passed back to any program that called it. This may not seem like much of a problem to you at this point; but it *will* become important as you create more complex programs.
int main (): Returns a integer value at the end of execution. The value returned can be a standard 0 or any other int to represent and number of errors/choices/results/etc... int main () is a standard.
Go for int main (), if for no other reason than that it’s a good coding habit. It’s no harder to type "return 0;" than "return;", and it will save you time in the future.

No comments:

Post a Comment