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

Array big enough 2 numbers

Declare an array of type float named math_constants. The array should be big enough to hold 2 numbers.

An array start at 0, so that is the first number right? 1 should be the second number.

Why is: float math_constants[1]; // 2 numbers Wrong? And: float math_constants[2]; //3 Numbers??? right?

It might be a newbie mistake, but its confusing me.

1 Answer

Joe Timmons
Joe Timmons
4,331 Points

Hi Michael, No worries, it can be confusing at first. You are correct that when accessing an array, they do start at 0.

When you declare an array in Objective-C, you can specify the the actual number of memory addresses to create.

float math_constants[2];    //this declares you want two memory locations
math_constants[0] = 3.14;   //accesses the first location
math_constants[1] = 11.7;   //accesses the second location

Let me know if that helps clear up the difference between Accessing and Declaring arrays!

-Joe

Thank you Joe, i now understand it.