0
0
Goprogramming~5 mins

Address and dereference operators in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the address operator (&) do in Go?
The address operator (&) gives the memory address of a variable. It lets you find where the variable is stored in memory.
Click to reveal answer
beginner
What does the dereference operator (*) do in Go?
The dereference operator (*) lets you access or change the value stored at a memory address (pointer). It "follows" the pointer to the actual data.
Click to reveal answer
beginner
Given: var x int = 10; p := &x; What is *p?
*p is 10, the value stored at the memory address p points to (which is x's value).
Click to reveal answer
intermediate
How do you change the value of a variable using a pointer in Go?
Use the dereference operator (*) on the pointer to assign a new value. For example, *p = 20 changes the value at the address p points to.
Click to reveal answer
intermediate
Why are address and dereference operators useful in Go?
They let you work directly with memory addresses, which helps with efficient data handling, sharing data without copying, and building complex data structures like linked lists.
Click to reveal answer
What does the & operator do in Go?
AReturns the memory address of a variable
BAccesses the value at a pointer
CDeclares a new variable
DPerforms addition
What does *p mean if p is a pointer in Go?
AThe value stored at the address p points to
BCreates a new pointer
CDeclares a pointer variable
DThe memory address stored in p
How do you get the address of variable x in Go?
Aaddress(x)
B*x
Cx&
D&x
If p := &x, what does *p = 5 do?
AChanges p to 5
BChanges x to 5
CCreates a new variable 5
DCauses an error
Why use pointers in Go?
ATo declare variables
BTo copy data faster
CTo access memory addresses directly
DTo avoid using variables
Explain how the address (&) and dereference (*) operators work together in Go.
Think about how you find a house address and then enter the house to see what's inside.
You got /3 concepts.
    Describe a simple example in Go where you use a pointer to change a variable's value.
    Start with a number, get its address, then change the number through the pointer.
    You got /5 concepts.