Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dereference operator
* instead of the address operator &.Using symbols like
# or $ which are not valid operators.✗ Incorrect
The address operator in Go is
&. It returns the memory address of the variable.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the address operator
& instead of dereference *.Using invalid operators like
^ or %.✗ Incorrect
The dereference operator
* is used to access the value stored at the memory address a pointer holds.3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning directly to the pointer variable instead of dereferencing it.
Using invalid syntax like
ptr* or &ptr.✗ Incorrect
To update the value that a pointer points to, use the dereference operator
* before the pointer variable.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators in the blanks.
Using invalid operators like
# or $.✗ Incorrect
First, use
& to get the address of val. Then use * to dereference the pointer and get the value.5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pointer variable
ptr directly instead of dereferencing.Mixing up the address and dereference operators.
✗ Incorrect
Use
& to get the address of num. Use *ptr to update and access the value via the pointer.