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) Pointers and Memory Pointers

Assign the variable "pointy" the address of "alpha".

I need help Assigning the variable "pointy" to the address of "alpha". My code is:

char *pointy;
char alpha = 'k';
*pointy = α
    ``` 
I think I'm correct but its wrong. Please Help.

QUOTE: " *pointy = α I think I'm correct but its wrong. "

take out the pointer in 'pointy'. so it reads:

pointy = α

2 Answers

Matthew Mascioni
Matthew Mascioni
20,444 Points

Hey!

Hmm... You seem to be doing everything right, but I think it might be a good idea to quickly review setting a variable vs. setting the value of it. In the first part of the challenge, you declared a pointer variable (of type char) named pointy. I'm going to declare one named 'theScore', of type int.

int *theScore;

Note that the asterisk (*) denotes the variable being a pointer.

Say I created another int named score, not initializing it. It would look like this:

int score;

However, if I wanted to set the value of score, I would use the = sign to accomplish this, like so:

score = 72;

(for once, I'm good at sports!)

Pointers work the exact same way. If I wanted to set the pointer theScore to the memory address of score:

theScore = &score;

We only use the asterisk (*) when declaring a new pointer. This becomes very prominent when you start working more with Objective-C. If I declared and initialized this, for example:

NSString *string = @"Hello!";

I'd change the value by doing this:

string = @"New value!";

Hope this helps!

Thank You for the answer! Helped out so much!