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 Arrays

arrays help !

i need help on the 2nd array question it doesnt teach you in the videos it only shows you the floats instead of char

Stone Preston
Stone Preston
42,016 Points

please post the code you have tried so far

5 Answers

Mike Baxter
Mike Baxter
4,442 Points

The OP's code challenge appears to have been:

Declare 2 separate variables of type char named "alpha" and "bravo". Assign the letter 'a' to the variable "alpha" and the letter 'b' to "bravo".

It turns out that if you use double-quotes, it makes a string rather than a character. Therefore, the following is wrong (because it does not make a character, it makes a string literal):

char alpha = "a";

You'd want to do it like this:

char alpha = 'a';

I found the answer on Stackoverflow after a little Googling.

Mike Baxter
Mike Baxter
4,442 Points

Jason Almenas , suppose I want to make a float array with a size of 5. I would do so like this:

float numbers[5];

// Remember that arrays are zero-indexed—they start at zero.
float[0] = 100;
float[1] = 200;
float[2] = 300;
float[4] = 400;
float[5] = 500;

'float's are like 'char's in that you can replace the word 'float' and put 'char' instead. So now you can take that code I made above and change the number from 5 to 2, since you need only two elements in the 'char' array.

Rather than adding a number like I did, you can add a 'char' through a variable name, like this:

letters[0] = alpha;

And so on. I'm trying to avoid answering the question directly, because I think it's easier to learn when you have to figure things out a little bit on your own.

I was about to make a post about the same question.

I understand how to create the two declarations in the first question, but if I am correct the second question in the Array quiz asks "Declare an array of type 'char' called "letters" with a size of 2. Assign the variable "alpha" as the first element of the array "letters"."

And I've very confused on what is being asked.

Oh I didn't see that you answered back, thanks a lot I appreciate the help along with not giving me the answer outright. :)

Wow, so I just got passed it. Apparently I should not have deleted the first answers to the Question 1. Once I reentered that above my Question 2 answer, I got it right. Thanks again for the help.