FAQ: Learn Go: Addresses and Pointers - Pointers

This community-built FAQ covers the “Pointers” exercise from the lesson “Learn Go: Addresses and Pointers”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Go

FAQs on the exercise Pointers

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Maybe I’m wrong, but I think I may have found an error in the code checks on this lesson. I was at the point in the lesson where it says, "1. Given the string star , create a pointer called starAddress that holds the address of star .

I used the following code:

func main() {
star := “Polaris”
// Add your code below:
var starAddress *string
starAddress = &star
fmt.Println(“The address of star is”, starAddress)

This code did not pass the check for step one. It gives me the following error:

Did you assign starAddress the address of star ?

However, my code ran fine and even gave me my intended output:

The address of star is 0xc0000101e0

Am I not understanding this correctly? I declared my variable, starAddress, and used the asterisk to state that this would hold the address for a string variable. I then set the value of starAddress to the address of the star variable using the ampersand.

The hint states, “You may initialize starAddress first and then assign it a value or directly declare it using := .”

If I change my code to the following, it passes the first check:

func main() {
star := “Polaris”
// Add your code below:
starAddress := &star
fmt.Println(“The address of star is”, starAddress)

However, if I’m understanding it correctly, what I did differently here was directly declare it instead of declaring it first and then assigning a value. If this is the case, either the hint is incorrect that I can declare it first and then assign it a value or the code check is incorrect and not allowing me to do so.

After passing the first check, I changed my code back to what I used first, declaring my variable and then setting a value, and it passed the second check and ran fine, again giving my my intended output:

The address of star is 0xc0000101e0

If I’m wrong, please explain how so that I can better understand this. Any help would be very much appreciated.

I don’t think you are wrong. I have this issue with many of the test on this site. Sometimes the test and lesson is designed to enforce something specific. In this case I think its just the test. My code was the last code snippet you posted.