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

Eileen Zimmerman
Eileen Zimmerman
3,047 Points

Objective-C Basics Code Challenge: Array Length

I cannot seem to pass step 2 of this challenge despite having run the code successfully in XCode.

The challenge says: "Using the printf function print the size in bytes of the variable "real_numbers". Your output should look like the following: "Array real_numbers is x bytes."

This is the code I wrote: float real_numbers[5]; printf("array real_numbers is %ld bytes\n", sizeof(real_numbers)/sizeof(float));

I get this error from Treehouse: Bummer! Make sure you are calling printf and passing a string (not an NSString) and "real_numbers" as the parameters. The correct format option is '%ld'.

In Xcode the console correctly returns: array real_numbers is 5 bytes

What am I doing wrong here? Thanks for your help in advance.

2 Answers

Eileen Zimmerman
Eileen Zimmerman
3,047 Points

Wow, I feel like I just got an email from a celebrity! Thanks for the response Amit. Guess I tried to overcomplicate the challenge, haha.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

You are almost right except that the challenge is asking only for the size of the real_numbers array and not the length of the real_numbers array. 5 is the length of the array and does not say how many bytes it contains. sizeof(real_numbers) will give you the size of the array in bytes.