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 trial

iOS Objective-C Basics (Retired) Fundamentals of C Anatomy of a C program

Return Value

Can 'main function' return a value expect 0? Is it because we use int, we should use an integer value? Can we use float rather than int? Actually is it really necessary to use return? For example can we just use printf at the end of the function for checking?

2 Answers

if you just used a printf statement at the end, the compiler would throw you an error, because you have reached the end of a non-void statement.

The "int" before main indicates that the main function expects you to return an integer, not doing this or returning anything else will cause errors.

The return value of the main function defines the exist status of the program as it is exited. You can do all kinds of stuff in between the execution of the main function, but eventually you should return something as to provide the status to the system.