0
0
Goprogramming~10 mins

Address and dereference operators 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 get the address of variable num.

Go
num := 10
ptr := [1]num
fmt.Println(ptr)
Drag options to blanks, or click blank then click option'
A*
B&
C#
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dereference operator * instead of the address operator &.
Using symbols like # or $ which are not valid operators.
2fill in blank
medium

Complete the code to access the value stored at the pointer ptr.

Go
num := 20
ptr := &num
value := [1]ptr
fmt.Println(value)
Drag options to blanks, or click blank then click option'
A*
B&
C^
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using the address operator & instead of dereference *.
Using invalid operators like ^ or %.
3fill in blank
hard

Fix the error in the code to correctly update the value via pointer.

Go
num := 5
ptr := &num
[1]ptr = 10
fmt.Println(num)
Drag options to blanks, or click blank then click option'
Aptr*
Bptr
C*
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning directly to the pointer variable instead of dereferencing it.
Using invalid syntax like ptr* or &ptr.
4fill in blank
hard

Fill both blanks to create a pointer to val and then get its value.

Go
val := 15
ptr := [1]val
result := [2]ptr
fmt.Println(result)
Drag options to blanks, or click blank then click option'
A&
B*
C#
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators in the blanks.
Using invalid operators like # or $.
5fill in blank
hard

Fill all three blanks to create a pointer, update the value via pointer, and print the updated value.

Go
num := 8
ptr := [1]num
[2]ptr = 20
fmt.Println([3]ptr)
Drag options to blanks, or click blank then click option'
A&
B*
Cptr
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pointer variable ptr directly instead of dereferencing.
Mixing up the address and dereference operators.