Challenge - 5 Problems
Pointer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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) }
Attempts:
2 left
💡 Hint
Remember that *p gives the value stored at the address p points to.
✗ Incorrect
The pointer p holds the address of x. Using *p accesses the value at that address, which is 10.
❓ Predict Output
intermediate2: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") } }
Attempts:
2 left
💡 Hint
Uninitialized pointers have the zero value nil.
✗ Incorrect
The pointer p is declared but not assigned, so it defaults to nil. The if condition detects this and prints accordingly.
❓ Predict Output
advanced2: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) }
Attempts:
2 left
💡 Hint
Changing the value via pointer changes the original variable.
✗ Incorrect
The pointer p points to x. Assigning *p = 20 changes x to 20. So printing x outputs 20.
❓ Predict Output
advanced2:00remaining
Pointer declaration syntax error
Which option will cause a compilation error in Go?
Attempts:
2 left
💡 Hint
A pointer must hold an address or nil, not a direct value.
✗ Incorrect
Option B tries to assign an int value directly to a pointer variable, which is invalid. The others are valid pointer declarations or assignments.
🧠 Conceptual
expert2:00remaining
Pointer zero value and usage
Which statement about pointer declaration in Go is TRUE?
Attempts:
2 left
💡 Hint
Think about what happens when you declare a pointer but don't assign it.
✗ Incorrect
In Go, uninitialized pointers have the zero value nil, which means they don't point to any valid memory. Dereferencing nil causes a runtime panic.