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) Pointers and Memory Array Size and Length

Help with printf function for how many items an array can hold.

This is what I have so far: float real_numbers [5]; {

printf ("Array real_numbers is %ld bytes.\n", sizeof real_numbers);

printf ("Array real_numbers can store %ld items.\n", sizeof (real_numbers)); } Line 3 is from step two and that passed, Line 4 is from step 3 and did not pass. Also I do not know if I am supposed to keep the code from step 2 and add to it.

1 Answer

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Michael,

you need to keep the code from the last steps and you have to divide the size of the real_numbers array by the size of one float to determine the amount of numbers the array can store.

So Challenge task 3 of 3 of "Print the length of the array real_numbers using the sizeof() function. Your output should look like the following: Array real_numbers can store x items." would be:

float real_numbers[5];
printf("Array real_numbers is %ld bytes.\n", sizeof(real_numbers));
printf("Array real_numbers can store %ld items.\n", sizeof(real_numbers)/sizeof(float));