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

Andrew Shook
Andrew Shook
31,709 Points

Objective-C Basics Arrays Code Challenge 1 of 4

If you get stuck on this code challenge make sure that you are using single quotes and not double quotes. In C, single quotes and double quote have different meanings. A set of single quotes around the letter 'a' creates a character literal, while using double quotes around a letter creates a string. The difference between the two is that the string "A" contains the letter A and a null terminator.

Travis Favaron
Travis Favaron
13,038 Points

Very helpful. Thanks for the tip! I couldn't figure out what was going wrong.

Andrew Shook
Andrew Shook
31,709 Points

The reason that strings and chars are different variable types in C has to do with how they are stored in memory. In C strings are stored in memory as an array of chars, but since all information stored in a computer's memory is stored as a binary numbers and strings can have varying lengths there needed to be a way to differentiate true numeric arrays and string arrays. So it was decided that string arrays would have the last index in the array be null. That way the program would know to stop converting the binary numbers back into characters. If there was no null terminator at the end of string arrays the computer would read the next memory space after the string was suppose to end and convert that number stored in memory into a character. So at some point during the development of the C programming language it was decided that chars would use single quotes and strings would used double quotes to distinguish the two.

1 Answer

Alex Hamilton
Alex Hamilton
4,103 Points

ha... I was scratching my head for a few minutes on that one! printf("letters %c %c", letters[0], letters[1]);