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

Victor Ngo
Victor Ngo
8,324 Points

[False Alarm] Possible Error on Challenge 3 of 4

I think there's an error on this challenge. It asks to assign a number to the first index of an array. I did what it told me to but still had a red flag.

6 Answers

Patrick Donahue
Patrick Donahue
9,523 Points

That is weird.

So I did the challenge over and I got the same error. So to get passed it I changed float math_constants[1] to math_constants[3] and it worked. Not sure what the error really is.

Patrick Donahue
Patrick Donahue
9,523 Points

Can you post your code please?

Victor Ngo
Victor Ngo
8,324 Points

Challenge task 3 of 4

Assign the number 1.41421 to index 1 of math_constants.

My Code: float math_constants[1]; math_constants[0] = 2.71828; math_constants[1] = 1.41421;

And the response I got was: Bummer! As a reminder, arrays are 'zero-based'. Assigning a number to an array would look something like: name_of_array[0] = 1;

Victor Ngo
Victor Ngo
8,324 Points

Changing float math_constants[1] to math_constants[2] worked as well. Woohoo! Got the badge! Thanks for the post :D

Patrick Donahue
Patrick Donahue
9,523 Points

So I looked it up - in C the number in brackets is the amount of array places. Since we had [1] - that means there is only math_constants[0].

Example: char arr[4];// for accommodating 3 characters and one null '\0' byte.

Victor Ngo
Victor Ngo
8,324 Points

Oh, I thought when you initialize an array, that the number in brackets started counting elements from the zeroth element. Thanks for clearing that up!

Patrick Donahue
Patrick Donahue
9,523 Points

No problem! I needed a refresher on C arrays!