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 functions to access and modify the original variable's value directly.
Click to reveal answer
beginner
How does passing a pointer to a function differ from passing a value?
Passing a pointer sends the memory address, so the function can change the original variable. Passing a value sends a copy, so changes inside the function do not affect the original variable.
Click to reveal answer
beginner
What does the * operator do when used with a pointer inside a function?
The * operator dereferences the pointer, meaning it accesses or modifies the value stored at the memory address the pointer holds.
Click to reveal answer
intermediate
Why might you use a pointer parameter in a function?
You use a pointer parameter to allow the function to modify the original variable's value or to avoid copying large data structures for efficiency.
Click to reveal answer
intermediate
What happens if you try to modify a pointer parameter without dereferencing it?
Modifying the pointer itself changes the address it points to, not the value at that address. To change the original value, you must dereference the pointer.
Click to reveal answer
What does passing a pointer to a function allow you to do?
✗ Incorrect
Passing a pointer allows the function to access and modify the original variable's value directly.
In Go, what does the * operator do when used with a pointer inside a function?
✗ Incorrect
The * operator dereferences the pointer, letting you access or change the value it points to.
If you pass a variable by value to a function, what happens when you modify it inside the function?
✗ Incorrect
Passing by value sends a copy, so changes inside the function do not affect the original variable.
What is a common reason to use pointers in function parameters?
✗ Incorrect
Pointers help avoid copying big data and let functions modify the original variable.
What happens if you assign a new value to a pointer parameter without dereferencing it?
✗ Incorrect
Assigning to the pointer itself changes the address it holds, not the value at that address.
Explain how pointers behave when passed to functions in Go and why this is useful.
Think about how memory addresses let functions change variables outside their scope.
You got /4 concepts.
Describe the role of the * operator when working with pointers inside functions.
Consider how you get from an address to the actual value.
You got /3 concepts.