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 trialMegan Bullington
6,245 PointsI have a few questions. I thought chars could only store a single letter. Also, why does the array not have curly braces
Finally, what is %s?
2 Answers
David Rynn
10,554 PointsYou are correct, normally a variable of type char would store only one letter. However, in this example he uses:
char bravo[] = "bravo";
Notice the brackets after bravo? That means it's an array of char objects. It could also be written like this:
char bravo[6] = {'b', 'r', 'a', 'v', 'o', '\0'};
Another weird thing in C is that you have to end arrays of chars with '\0'. Surrounding the entire word in quotes is shorthand (char bravo[]="bravo"; ), in the C language, for the same thing. In other programming languages an array of char letters is called a "string".
And that's why the array doesn't have curly brackets - it's shorthand for an array of chars in C. It's a shortcut built into the C language. It's only used this way for chars, so you would never see:
//this is bad code, don't do this:
int someNumber[] = "123,246.55";
oh and finally, in a printout use of '%' followed by a letter indicates a place holder. So after the quotations are closed, the variables listed separated by commas will replace the '%' in order. That symbol is followed by a letter corresponding to an integer or a float or a char, etc (I don't remember which is for what - %s is for chars I think, but you should look up the rest or just trust what the instructor wrote).
Hope this helps.
Jayden Spring
8,625 PointsA char value is 1 byte and are encoded as numbers following the ASCII encoding. This can be letters, numbers and non-alphanumeric characters.
For example, a would be the char code of the number 2 is 50 (I think of the top of my head).
As for curly braces - it is the syntax of Obj C and this follows in Swift. It is as you are in effect sending a message to an object, its Obj C's way of making the syntax look more objective I think (personally!).