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
Colton Whited
516 PointsPrint 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.
This challenge comes from iOS development under C basics. I am almost done My thing with posting on this is I have to try for as long as I can, and then wait and try again the next day. I'm sure I'm only missing something small which is super frustrating, but here is what I have so far
Challenge 1:float real_numbers [5]; Challenge 2:printf ("Array real_numbers is %ld bytes.\n", sizeof (real_numbers)); Challenge 3: printf ("Array real_numbers can store %ld items.\n", sizeof (real_numbers)/sizeof (floats);
4 Answers
eirikvaa
18,015 PointsYou are dividing by the sizeof(floats) when you should divide by the sizeof(float):
float real_numbers[5];
printf("Array real_numbers can store %ld items.\n", sizeof(real_numbers)/sizeof(float));
RASHU BHATNAGAR
Courses Plus Student 2,669 Pointsfloat 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)));
Hi Colton looking at the 3rd line (sizeof(real_numbers)/sizeof(float)));
you need to enclose the sizeof(real_numbers)/sizeof(float) with in parenthesis and then it should work fine.
Brandon Ross
1,971 PointsHopefully to spare some people headache in the future... You must include code from the previous answer (I had refactored the second line to answer this specific question and thereby invalidated the answer).
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));
Also RASHU BHATNAGAR although it is not terrible to include it, it is also not necessary to include the additional parentheses: see Eirik Vale Aase answer above.
Riken Patel
659 Pointsremove . after items