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

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!