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 Array

Do you always have to declare the length or size of an array in C?

In other languages, JavaScript, PHP etc, it can be very useful to load dynamic data (perhaps from a database) in to arrays and therefore not define any length.

3 Answers

I'm not sure if you've been introduced to NSMutableArray yet, but it allows you to add and delete items from an array which is pretty much an array in other languages. In this case you can populate an array with a few methods at initialization that allow you to add items without specifying the array's size.

I just realized you said C, not Objective-C. In C, I don't believe there is a way to initialize an array without a specific size. You can however, make an array inside a loop that's created based on a number taken from user input.

I know it is pretty easy to make a dynamic array in C++ but I am not sure if is in C. The best solution i could think of was said by Ricardo. "You can however, make an array inside a loop that's created based on a number taken from user input."

Thanks Guys

I'm working through the Treehouse iOS tute and not sure yet if, when I eventually reach the point where I develop a simple app, I'll be writing in C or C++. I think it's Objective C?

If you follow the treehouse tutorial and write an app it will be in Objective-C.