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

Igor Kletsov
Igor Kletsov
7,556 Points

Challenge task 3 of 3

Task-3
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.

his is how I did it:

float real_numbers [] = {1.1, 2.2, 3.3, 4.4, 5.5};  
printf ("Array real_numbers can store %ld items", sizeof(real_numbers)/sizeof(float));

It works everywhere, but: Bummer: Oops! It looks like Task 2 is no longer passing.

What is wrong ?
Screenshots: Task-1 Task-2 Task-3

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

You need to add to the task so don't delete the printf statement from the second task.

4 Answers

You changed your coding from task 2. You put:

("Array real_numbers can store %ld items", sizeof(real_numbers)/sizeof(float))

When you should have left the task 2 printf statement how it was. Try putting the task 2 printf statement back and creating a new printf statement with the code you had.

Igor Kletsov
Igor Kletsov
7,556 Points

Thank you. Everything works now!

Igor Kletsov
Igor Kletsov
7,556 Points

Thanks to all.

I have not noticed: Important: The code you write in each task should be added to the code written in the previous task.

Step 3 requires both step 2 and step 3 printf statements. The wording is very confusing.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The task is asking you to print the size of the array in bytes and not the length of the array. When you divide it by sizeof(float) you get the number of items but that's not what the challenge is asking for.

Igor Kletsov
Igor Kletsov
7,556 Points

Please read carefully : Challenge task 3 of 3 --> "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."