Recall & Review
beginner
What happens when you pass a value to a function in Go?
The function receives a copy of the value. Changes inside the function do not affect the original variable.
Click to reveal answer
beginner
What is a pointer in Go?
A pointer holds the memory address of a variable, allowing functions to access and modify the original variable directly.
Click to reveal answer
intermediate
How do you declare a pointer parameter in a Go function?
Use an asterisk (*) before the type in the function parameter, for example: func f(p *int) {}
Click to reveal answer
intermediate
Why use pointers instead of passing values?
Pointers allow functions to modify the original data and can be more efficient for large data structures because they avoid copying.
Click to reveal answer
beginner
What does the & operator do in Go?
It returns the memory address of a variable, creating a pointer to that variable.
Click to reveal answer
What does passing a value to a function in Go do?
✗ Incorrect
Passing a value sends a copy, so the original variable is not changed.
How do you pass a pointer to a function in Go?
✗ Incorrect
You use & to get the address when calling and * in the function parameter to receive the pointer.
What does the * operator do when used with a pointer in Go?
✗ Incorrect
The * operator accesses the value stored at the pointer's address.
Why might you prefer passing a pointer over a value?
✗ Incorrect
Passing a pointer lets the function change the original variable.
What happens if you change a value inside a function that received a copy?
✗ Incorrect
Changes to the copy do not affect the original variable.
Explain the difference between passing a value and passing a pointer to a function in Go.
Think about what happens inside the function when you change the parameter.
You got /4 concepts.
Describe how to declare and use a pointer parameter in a Go function.
Remember the & and * operators and their roles.
You got /4 concepts.