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

Challenge Task 2 of 3

I keep getting an error on Task 2 of 3 which asks to print the size of the array. It doesn't like my "%ld" and I have no idea what I can do to get the code working. Can anyone tell me what is wrong with my code:

float real_numbers [5]; printf ("Array real_numbers is %lb bytes\n", sizeof(real_numbers));

6 Answers

Stone Preston
Stone Preston
42,016 Points
float real_numbers [5]; printf ("Array real_numbers is %lb bytes\n", sizeof(real_numbers));

you used %lb instead of %ld

Thank you for your help Stone. I used percent, letter "l" as in letter and letter "d" as in dog. %ld. I am using a PC and I think it doesn't like my characters. I copied an pasted your code into the assignment and got the same error.

Hi Joyce,

Try %ld.

Thank you kindly for your help. One clarification is it an "l" as in "length" and a "d" as in dog? This is what I'm using on my PC but the character looks like a number one "1" when it is written.

Stone Preston
Stone Preston
42,016 Points

yes thats correct. l as in length and d as in dog. %d is for ints, however putting the l in front (%ld) means its for a long int which can store larger numbers (such as sizes in bytes which could be fairly long)

Thank you Stone and Jason for your help.

I am using the correct format. It is my PC and the homework work space that are at war.

I tried copying both of your "%ld" into the workspace and end up with an error. Completely frustrating!

I'm on a pc myself and it is passing fine for me.

I copied Stone Preston 's code and change the 'b' as in boy, to a 'd' as in dog, and it passes.

Stone Preston
Stone Preston
42,016 Points

hmm thats strange. just copied in your original answer but changed the format specifier and passed using

float real_numbers [5]; 
printf ("Array real_numbers is %ld bytes\n", sizeof(real_numbers));

My original code had "b" instead of a "d" and I looked at it 10 times and didn't see it.

Greatly appreciate the help Stone and Jason. I was tearing my hair out and I managed to write the code for three assignments once this was fixed. :)