Recall & Review
beginner
What is a pointer in Go?
A pointer in Go is a variable that stores the memory address of another variable. It allows you to directly access and modify the value stored at that address.
Click to reveal answer
beginner
How do you declare a pointer to an int variable in Go?
You declare a pointer to an int using the syntax:
var p *int. Here, p is a pointer that can hold the address of an int variable.Click to reveal answer
beginner
What does the * operator do when used with a pointer variable?
The * operator is used to dereference a pointer, which means accessing or modifying the value stored at the memory address the pointer holds.
Click to reveal answer
beginner
How do you get the address of a variable in Go?
You use the & operator before a variable name to get its memory address. For example,
p = &x assigns the address of x to pointer p.Click to reveal answer
intermediate
Why use pointers in Go?
Pointers let you share and modify data efficiently without copying it. They are useful for changing variables inside functions and managing memory directly.Click to reveal answer
Which symbol is used to declare a pointer type in Go?
✗ Incorrect
The * symbol is used to declare a pointer type, for example, *int means a pointer to an int.
What does the & operator do in Go?
✗ Incorrect
The & operator returns the memory address of a variable.
How do you access the value stored at the address a pointer holds?
✗ Incorrect
The * operator dereferences the pointer to access the value at its address.
What is the type of variable p after this declaration: var p *int?
✗ Incorrect
p is declared as a pointer to an int type.
Why might you use pointers in Go?
✗ Incorrect
Pointers allow functions to modify variables directly by passing their addresses.
Explain how to declare a pointer to an int and assign it the address of an int variable in Go.
Think about how you declare a pointer and how you get the address of a variable.
You got /4 concepts.
Describe what happens when you dereference a pointer in Go and why it is useful.
Consider what * does when used with a pointer variable.
You got /4 concepts.