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 Arrays

Keiron Lowe
Keiron Lowe
2,993 Points

math_constants length

The code challenge is asking me to create an array large enough to hold 2 numbers. If arrays are 0 based, wouldn't the answer be float math_constants[1] rather than float math_constants[2]?

The first number would be math_constants[0] and the second math_constants[1], so unless I'm missing something I think the answer for this challenge is wrong.

1 Answer

Hey Keiron,

That is a great question. When you initialize an array is different than, when you accessing it by the index. This means that this array:

float array_one[5];

will have 5 elements of type floats. Remember this is initializing the array. But to access it is based 0. Think about it this way. When initializing you have the compiler how many elements you one.

I hope it makes sense,