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) Pointers and Memory Array Size and Length

Cauli Tomaz
Cauli Tomaz
12,362 Points

An array that holds 5 floats

Should be float real_numbers[4], not float real_numbers[5], right?

3 Answers

Stone Preston
Stone Preston
42,016 Points

no, when declaring an array the number you put in the brackets is the length of the array. So in this case since the length needs to be 5, you would use 5.

its not like with array indexing and you want to get the first element in the array so you use index 0. This is different, although I understand your confusion

Andrew Shook
Andrew Shook
31,709 Points

No, when you declare an array, which is what you are doing, the number you put in is not a zero index. So if you what the array to hold 5 things you have to put 5. This might seem confusing, since when you access the last element of an array with 5 items you would use 4. For now just remember that when you create an array you put the actually number of things you want to store in the array inside the square braces. When you want to access a value in an array you take it position in the array and subtract 1.

Cauli Tomaz
Cauli Tomaz
12,362 Points

Wow, what a noobie I am. Thanks guys!