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

zaakir Hamzavi
zaakir Hamzavi
Courses Plus Student 307 Points

Are implementations things like int and float?

Implementations of functions are things like float and int right?

Also this was a question for a challenge my answer is there to why is my answer right can you explain it?

Implement a function named "addTwo" that returns the sum of two floats. The function will accept two float numbers as arguments. It should add the two arguments together, and return the result. (No need to write the main function. Just write out the implementation for the addTwo function.)

float addTwo (float a, float b) {return a+b;}

2 Answers

You are creating a function that adds two floats together like this:

float addTwo (float x, float y) { return x + y; }

So the float named "addTwo" is made of two variables or in other terms take two parameters, float x and float y. them you tell the complier with your return code to add the floats.but theres no need to say return float a + float b because you have already told the complier what time of variable it is with your static code.

say if x = 1 and y = 2 are the floats in your parameter then you are going to get ยฃ back when the complier runs your code.

Hope that explains it

Hi zaakir,

int and float are data types.

The implementation of a function is also known as the function definition.

Your answer was: float addTwo (float a, float b) {return a+b;}

That whole thing is the function definition or implementation.

It has the return data type, the function name, the data types of the parameters, and also the body of the function which is what comes between the curly braces { } This is the code that's going to be be executed whenever this function gets called.