Challenge - 5 Problems
Pointer Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pointer dereference after assignment
What is the output of this Go program?
Go
package main import "fmt" func main() { x := 10 p := &x *p = 20 fmt.Println(x) }
Attempts:
2 left
💡 Hint
Remember that *p changes the value at the address p points to.
✗ Incorrect
The pointer p points to x. Changing *p changes x's value to 20. So printing x outputs 20.
❓ Predict Output
intermediate2:00remaining
Value of variable after pointer reassignment
What will be printed by this Go code?
Go
package main import "fmt" func main() { a := 5 b := 10 p := &a p = &b *p = 15 fmt.Println(a, b) }
Attempts:
2 left
💡 Hint
Pointer p is first set to a, then to b. Changing *p affects which variable?
✗ Incorrect
Initially p points to a, then it points to b. Changing *p = 15 changes b to 15. a remains 5.
🔧 Debug
advanced2:00remaining
Identify the error in pointer usage
What error does this Go code produce?
Go
package main func main() { var p *int *p = 10 }
Attempts:
2 left
💡 Hint
p is declared but not initialized to point to valid memory.
✗ Incorrect
p is a nil pointer. Dereferencing it (*p) causes a runtime panic due to invalid memory access.
🧠 Conceptual
advanced2:00remaining
Effect of pointer on function argument
What will be the output of this Go program?
Go
package main import "fmt" func increment(n *int) { *n = *n + 1 } func main() { x := 7 increment(&x) fmt.Println(x) }
Attempts:
2 left
💡 Hint
The function changes the value at the address passed.
✗ Incorrect
increment receives a pointer to x and increases the value at that address by 1, so x becomes 8.
❓ Predict Output
expert2:00remaining
Pointer arithmetic and dereference behavior
What is the output of this Go program?
Go
package main import "fmt" func main() { arr := [3]int{1, 2, 3} p := &arr[0] fmt.Println(*p) p = &arr[1] fmt.Println(*p) p++ fmt.Println(*p) }
Attempts:
2 left
💡 Hint
Go does not support pointer arithmetic like p++.
✗ Incorrect
In Go, you cannot increment pointers with ++. This causes a compilation error.