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

dovlavi
dovlavi
358 Points

Hold two numbers or three?

The challenge says that it "should be big enough to hold 2 numbers" - but then surely the array should be math_constants[1] and not math_constants[2] since index [0] of the array would hold the first number and index [1] would hold the second number. So I'm not sure why it has to be math_constants[2] instead of math_constants[1].

2 Answers

Stone Preston
Stone Preston
42,016 Points

when declaring an array, the number that goes inside the brackets is the size of the array. you are not indexing the array when you declare it.

To declare an array with a size of 5:

//this can hold 5 floats
float someArray[5];

to set the first element of the array using an index

someArray[0] = 1.0;

When indexing arrays, the indexes start at 0, so if you want the first element you use index 0, the second is index 1 etc etc.

dovlavi
dovlavi
358 Points

Thank you Stone!