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) Functional Programming in C Functions

Jianhui Li
Jianhui Li
287 Points

What is return really do?

I am really confused about the return a + b + 343, according to this tutorial, seems like it's overwriting the value of funky_math(foo,bar) in the printf section.

So I was wondering if it's true that once I use return in the implementation section, it will automatically replay the value in the printf section?

2 Answers

I'm not quite sure what you mean by "automatically replay the value in the printf section" but the value of the return statement replaces the reference to the function. Instead of

int result = funkymath(numberA,numberB)

, whatever value the return statement returned would replace the call to the function, so in the context of this video, the previous statement would actually mean

int result = numberA+numberB+343
``` . 
Sorry if this wasn't what you asked!

Jianhui, the return statement returns a value, in this case an int; to the place where the function was called (in this case inside the printf statement).