Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmoadw
Courses Plus Student 273 PointsWhy the main function always returns 0? what is the point of that?
Just don't find the reason for that,
3 Answers
Ron McCranie
7,837 PointsThe Main()
function requires an integer to be returned to tell the application that the Main()
function completed. Since the return type is int
or integer (at the begging of the function), you must return a whole number. Other functions might return a string or other type. This is mentioned in the last 60 seconds of the video if you'd like to review it.
Ricardo Hill-Henry
38,442 Pointsmain() doesn't always return 0. The main function can either return 0 or 1, which is equivalent to EXIT_SUCCESS and EXIT_FAILURE respectively. When main returns 0, this means there were no errors found in your program that will prevent building/compiling. When main returns 1, errors have occurred. I would assume 0 is always placed there because it makes more sense to assume the program is written correctly then check for errors.
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsWhat about void main() ? Is it used in pure C? I know we learned in school in 2003 to use void type on the main function for C++ -> is that still the same practice or did it change?
Thanks for answering.
moadw
Courses Plus Student 273 Pointsmoadw
Courses Plus Student 273 PointsFor sure the video has the explanation but still i was confused. Thank you so much.