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!

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) Beyond the Basics Pointers: Part 2

Louis Darby
Louis Darby
5,149 Points

Confusion about pointers

Hi, I just had a quick question about this video,

The function uses the letter x, however in the code block we have the letter i, but there is no reference to either of them being related. Basically, how does the function know that i is what needs to be substituted for x. Is the fact its a function outside the code block means it will take whatever integer variable within it and use it?

Does that mean if I declared another variable within the code block i.e. int b = 10 the function would work on this too?

Thanks for reading!

you are confusing the parameter x with a declared variable. x is the passed in parameter to the function.

1 Answer

Stone Preston
Stone Preston
42,016 Points

in the function definition of increment the name of the parameter is x. when he calls the increment function inside the main method he passes the variable i in as an argument.

When you call a function, the argument passed in does not have to be named the same as the parameter. it can be anything.

Note: when defining a function, the variables in the parenthesis are called parameters, when calling a function they are called arguments

for example if I had a function called add two I could define it like so:

float addTwo(float one, float two) {

return one + two
}
``

in the definition above the function takes two parameters, one and two. I reference those parameters in the body of the function definition.

when I call this function 

float a = 2.0; float b = 3.0; float c = addTwo(a, b);

I can use anything for the arguments

float d = addTwo(3.2, 5.7);