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 - Pointers & Memory Code Challenge

Hi,

I'm having trouble with the following from the Objective C - Pointers & Memory Code Challenge (task 2).

Using the printf function print the size in bytes of the variable "real_numbers". Your output should look like the following: "Array real_numbers is x bytes."

What I have is:

float real_numbers [] {1.1, 1.2, 1.3, 1.4, 1.5};
printf("Array real_numbers is %ld bytes."\n, sizeof(float));
return 0;

& my error message is:

Bummer! Make sure you are calling printf and passing a string (not an NSString) and "real_numbers" as the parameters. The correct format option is '%ld'.

Any suggestions on what I'm doing wrong?

http://teamtreehouse.com/library/array-length-2

5 Answers

Hi Stan

You want to do a sizeof(real_number) not float.

Hey Bradley,

Thanks! It looks like I had it confused with the second section of the example in the video. But does the float go for the 3rd part?

I'm having trouble with the next step, which 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."

I have

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

which also comes out incorrect.

*****Never mind - got it.

Part 3 is basically sizeof(real_numbers)/sizeof(float))

I am tearing my hair out with this one in my ipad.

I'm entering:

float real_numbers [5] = {}; printf("Array real_numbers can store %ld items/n", sizeof(real_numbers)/sizeof(float));

It keeps marking it down and saying real_numbers is long and asking if I'm using %ld, which I am. I feel like I'm understanding the concept and what's going on.

Any tips on what I've got wrong?

Thanks

Hey Turd after items you have /n. For a newline character this should be \n after items don't know if this will fix your problem

Thanks, bradley!