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

2 Question for the anatomy of C

What does int main() means? What does it mean by saying this is the starting point of executing programs, and it is the only function been run in the program?

2nd, why do we need to return 0 at the end? What's the purpose of return?

2 Answers

In a C program, the main() function is the one that gets executed when you run your program. That's what the instructor means when he says it's the starting point. Whatever your program does, it has to be done in the main function, or called from it.

The int part, in front of the function name specifies the type of the return value. Functions can return values (but the main function must return a value), and those values can have different types. This function returns an integer.

The return statement returns the value from a function. In this case, it returns 0. Traditionally 0 has been used when a program is successful, and 1 when there are errors in the execution of your program.

Is it the main() function will be the only one been executed? and other will not been executed?

Why must a function return values?

Yes, if your program has several functions, only the main() function will get executed. To use any other functions, you will have to call them inside of main().

There are functions that don't return values (void functions) but the main() function must return a value. Programming was somewhat modelled after mathematics. In maths, a function produces outputs for certain inputs. Think of the return value as the function's output.

Lastly, a function is useless unless it does something. It either has to return a value, or have side effects (modify some state or call some other function). If it does neither, it doesn't change how the program works at all.

Thanks, I understand now. You are great at explaining stuff! Great job haha. And thanks. If I have question can I use a certain way so that i can notify you? :) :D

You can always tag someone in a post. Use the @ symbol and then start typing their name. A dropdown will appear, and you can select the person you want to tag, like this: Kirk Goh

Haha okay. Thanks so much Dino Paškvan :D