0
0
Goprogramming~10 mins

Struct pointers in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a pointer to a struct variable.

Go
var p [1] Person
Drag options to blanks, or click blank then click option'
A%
B&
C->
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of * to declare a pointer type.
Using -> which is not valid in Go.
2fill in blank
medium

Complete the code to assign the address of a struct variable to a pointer.

Go
p = [1]person
Drag options to blanks, or click blank then click option'
A&
B*
C->
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of & to get the address.
Using -> which is invalid in Go.
3fill in blank
hard

Fix the error in accessing a struct field through a pointer.

Go
fmt.Println(p[1]Name)
Drag options to blanks, or click blank then click option'
A.
B->
C*.
D&.
Attempts:
3 left
💡 Hint
Common Mistakes
Using -> which is invalid in Go.
Trying to dereference manually with *.
4fill in blank
hard

Fill both blanks to create a pointer to a struct and assign it.

Go
p := [1]Person[2]
Drag options to blanks, or click blank then click option'
A&
B*
C{}
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of & to get the address.
Using [] which is for slices, not structs.
5fill in blank
hard

Fill all three blanks to create a map with struct pointers and filter by a field.

Go
result := map[string]*Person{ [1]: [2]Person{Name: "Alice"} }
filtered := map[string]*Person{}
for k, v := range result {
  if v.Name [3] "Alice" {
    filtered[k] = v
  }
}
Drag options to blanks, or click blank then click option'
A"user1"
B&
C==
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using : instead of : in map literal key-value pair.
Not using & to get pointer to struct.
Using = instead of == for comparison.