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 trialJonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 Pointshttp://teamtreehouse.com/library/objectivec-basics/pointers-and-memory/array-size-and-length
Help me solve this
6 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Jonathan,
You have the correct output string and format specifier. The only problem is that printf
is expecting a second argument so that it can take that value and place it where you have the %ld
It's asking you to print the size of the array. You want to use the sizeof operator
printf ("Array real_numbers is %ld bytes.", sizeof(real_numbers));
notf0und
11,940 PointsPlease elaborate on your issue. It wouldn't be good for your learning if we simply handed you the answers :) Which task are you having troubles with?
rishavatreya
4,945 Pointsfloat real_numbers[5];
Jonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 PointsThanks for your answers. I'm trying to solve task 2 Here is my code:
float real_numbers[] = {1.1, 1.2, 1.3, 1.4, 1.5}; printf("Array real_numbers is %ld bytes");
Jonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 PointsGot it. Thanks for your help. Here is the final code for task 2. float real_numbers[5]; printf("Array real_numbers is %ld bytes", sizeof(real_numbers));
Jonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 Pointsthanks,
I'm trying to solve task 3 now Here is my code: <p> 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)); </p> what's wrong with my code
Jason Anello
Courses Plus Student 94,610 PointsYou want to divide the total size of the array by the size of a float to get the number of items.
sizeof(real_numbers) / sizeof(float)