Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,

-D