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) Fundamentals of C Variables

Sophie Phillips
Sophie Phillips
2,629 Points

passing a string instead of a NSString to printf

I dont understand what is meant by this!

2 Answers

Stone Preston
Stone Preston
42,016 Points

it means pass a string literal to printf as in

printf("This is a string literal with a format specifier %f for a float", someFloat);

the words between the " " are a string literal, not an NSString variable.

The challenge asks you to create a float with a value of 14, and then print it out so that the output reads "A ball with a radius of 14.5 inches".

float radius = 14.5;

printf("A ball with a radius of %f inches", radius);

notice that the value of radius is inserted into the string where the format specifer (%f) is.