0
0
Goprogramming~5 mins

Pointer declaration in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a pointer in Go?
A pointer in Go is a variable that stores the memory address of another variable. It allows you to directly access and modify the value stored at that address.
Click to reveal answer
beginner
How do you declare a pointer to an int variable in Go?
You declare a pointer to an int using the syntax: var p *int. Here, p is a pointer that can hold the address of an int variable.
Click to reveal answer
beginner
What does the * operator do when used with a pointer variable?
The * operator is used to dereference a pointer, which means accessing or modifying the value stored at the memory address the pointer holds.
Click to reveal answer
beginner
How do you get the address of a variable in Go?
You use the & operator before a variable name to get its memory address. For example, p = &x assigns the address of x to pointer p.
Click to reveal answer
intermediate
Why use pointers in Go?
Pointers let you share and modify data efficiently without copying it. They are useful for changing variables inside functions and managing memory directly.
Click to reveal answer
Which symbol is used to declare a pointer type in Go?
A&
B#
C*
D$
What does the & operator do in Go?
ADeclares a pointer
BDereferences a pointer
CAssigns a value
DGets the address of a variable
How do you access the value stored at the address a pointer holds?
AUsing the * operator
BUsing the & operator
CUsing the -> operator
DUsing the . operator
What is the type of variable p after this declaration: var p *int?
AInteger
BPointer to int
CPointer to string
DString
Why might you use pointers in Go?
ATo modify variables inside functions without copying
BTo create new variables
CTo convert types
DTo print values
Explain how to declare a pointer to an int and assign it the address of an int variable in Go.
Think about how you declare a pointer and how you get the address of a variable.
You got /4 concepts.
    Describe what happens when you dereference a pointer in Go and why it is useful.
    Consider what * does when used with a pointer variable.
    You got /4 concepts.