Recall & Review
beginner
What is a struct pointer in Go?
A struct pointer in Go is a variable that holds the memory address of a struct. It allows you to access and modify the struct's fields directly through the pointer.
Click to reveal answer
beginner
How do you declare a pointer to a struct in Go?
You declare a pointer to a struct by using the * symbol before the struct type. For example:
var p *Person declares a pointer to a Person struct.Click to reveal answer
beginner
How do you access struct fields using a pointer in Go?
You can access struct fields using the pointer with the dot operator directly, like
p.Name. Go automatically dereferences the pointer for you.Click to reveal answer
intermediate
What is the difference between a struct value and a struct pointer when passing to a function?
Passing a struct value copies the entire struct, so changes inside the function don't affect the original. Passing a struct pointer passes the address, so changes inside the function modify the original struct.
Click to reveal answer
intermediate
How do you create a new struct pointer with initialized values?
You can use the
new keyword or take the address of a struct literal. For example: p := new(Person) or p := &Person{Name: "Alice"}.Click to reveal answer
Which symbol is used to declare a pointer to a struct in Go?
✗ Incorrect
The asterisk (*) is used to declare a pointer type in Go, including pointers to structs.
How do you access a field 'Name' of a struct through a pointer 'p' in Go?
✗ Incorrect
In Go, you can access struct fields through a pointer using the dot operator directly, like p.Name. The language automatically dereferences the pointer.
What happens when you pass a struct pointer to a function?
✗ Incorrect
Passing a struct pointer allows the function to modify the original struct because it receives the address.
Which of these creates a new struct pointer with initialized values?
✗ Incorrect
Using &Person{...} creates a pointer to a new struct initialized with the given values.
What does the 'new' keyword do when used with a struct type?
✗ Incorrect
The 'new' keyword allocates memory for a zero-valued struct and returns its pointer.
Explain how struct pointers work in Go and how you can use them to modify struct data.
Think about how pointers let you work directly with the original data.
You got /3 concepts.
Describe two ways to create a struct pointer with initial values in Go.
One way uses 'new', the other uses & with curly braces.
You got /2 concepts.