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

Michael Reining
Michael Reining
10,101 Points

Please help stuck with simple array challenge - print the size in bytes of "real_numbers" array

The challenge is:

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

My input is:

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

When I enter the above code into Xcode it correctly prints the statement and tells me that the array is 20 bytes.

The error message says:

That was not the correct string. Do you have the correct format character? sizeof(real_numbers) returns a long. That format character is '%ld'.

Would appreciate some help so I can proceed and pass this challenge.

Michael Reining
Michael Reining
10,101 Points

Also, if anyone knows how to add a proper line break with markdown in post above please let me know so I can leave questions / comments that are more readable.

Lukasz R
Lukasz R
707 Points

What's the exact error code from web-editor? :)

Michael Reining
Michael Reining
10,101 Points

That was not the correct string. Do you have the correct format character? sizeof(real_numbers) returns a long. That format character is '%ld'.

Lukasz R
Lukasz R
707 Points

You have typo there: realy_numbers instead of real_numbers :)

Michael Reining
Michael Reining
10,101 Points

Doh! Thank you so much. No wonder that Xcode let it pass. Really appreciate your help

Lukasz R
Lukasz R
707 Points

No prob :) Just finished my 'objective-c basics' and had some time before proceeding to next steps :)

4 Answers

Michael Reining
Michael Reining
10,101 Points

Lesson: Pay more attention to typos in strings. ;)

float real_numbers []= {1, 2, 3, 4, 5}; printf("Array real_numbers is %ld bytes.", sizeof(real_numbers)/sizeof(float)); that's what i typed, what's wrong with this one?

float is not a whole number, it's a decimal or fraction like 0.3 or 0.56.

Chris Atlas
Chris Atlas
2,038 Points

can someone help me find my bug?

float real_numbers[5] = {2.1, 1.2, 2.3, 3.3, 4.5}; printf("array real_numbers %ld bytes\n", sizeof(real_numbers));

i don't think there is any need to make up those numbers,

real_numbers[5];

printf("Array real_numbers is %ld bytes.\n", sizeof(real_numbers));