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

Array length - online test either wrong or I'm going mad!

Hi,

Just sitting the tests on array length and pointer use in C and I've come across a problem (maybe!)

The questions (which the answer is a free text->compile answer) is:

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."

My answer is:

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

In xcode this works fine, using the online test this is wrong. Anyone tell me why? or highlight this to the web-code people to resolve.

Thanks!

5 Answers

Weird. I've re-done the test including the previous task line and now it's worked fine.

I just tried the same and had no errors. This is the answer

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

Make sure you are not replacing the 2nd line on the 3rd step!

Hi,

Thanks for replying. I think it was because I didn't include a previous answer in my answer. The compiler obviously checks to see the full history of all previous answers per task.

I am past this section now. Thank you.

Chris

Hi Guys,

I'm running into the same problem. I am typing it the same way as described above and I'm getting an error message. Please assist...

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

Hello,

I had the same type of issue. I just had to restart the quiz.