0
0
Goprogramming~20 mins

Pointer declaration in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pointer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pointer declaration and dereference
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    var x int = 10
    var p *int = &x
    fmt.Println(*p)
}
A0
BMemory address of x
C10
DCompilation error
Attempts:
2 left
💡 Hint
Remember that *p gives the value stored at the address p points to.
Predict Output
intermediate
2:00remaining
Pointer declaration with nil value
What will this Go program print?
Go
package main
import "fmt"
func main() {
    var p *int
    if p == nil {
        fmt.Println("Pointer is nil")
    } else {
        fmt.Println("Pointer is not nil")
    }
}
ARuntime panic
BPointer is not nil
CCompilation error
DPointer is nil
Attempts:
2 left
💡 Hint
Uninitialized pointers have the zero value nil.
Predict Output
advanced
2:00remaining
Pointer modification effect
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    x := 5
    p := &x
    *p = 20
    fmt.Println(x)
}
A20
B5
CCompilation error
DRuntime panic
Attempts:
2 left
💡 Hint
Changing the value via pointer changes the original variable.
Predict Output
advanced
2:00remaining
Pointer declaration syntax error
Which option will cause a compilation error in Go?
Avar p *int = nil
Bvar p *int = 10
C
var p *int
p = new(int)
D
var x int = 5
var p *int = &x
Attempts:
2 left
💡 Hint
A pointer must hold an address or nil, not a direct value.
🧠 Conceptual
expert
2:00remaining
Pointer zero value and usage
Which statement about pointer declaration in Go is TRUE?
AThe zero value of a pointer variable is nil, meaning it points to no valid memory.
BDereferencing a nil pointer returns zero without error.
CYou can assign an integer value directly to a pointer variable.
DA pointer variable declared without initialization points to a random memory location.
Attempts:
2 left
💡 Hint
Think about what happens when you declare a pointer but don't assign it.