Complete the code to declare a pointer to an integer variable.
var x int = 10 var p [1] = &x
In Go, a pointer to an int is declared as *int. The & operator gets the address of x.
Complete the code to change the value of x using its pointer p.
var x int = 5 var p *int = &x *p [1] 20 fmt.Println(x)
To change the value pointed to by p, use the assignment operator = with *p.
Fix the error in the code to correctly swap two integers using pointers.
func swap(a, b [1] int) { temp := *a *a = *b *b = temp } x, y := 1, 2 swap(&x, &y) fmt.Println(x, y)
The function parameters must be pointers to int, declared as *int, to modify the original variables.
Fill both blanks to correctly swap values of two integers using pointers.
func swap(a, b [1] int) { temp := *a *a = *b *b = temp } x, y := 3, 4 swap([2]x, &y) fmt.Println(x, y)
The function parameters must be pointers (*int), and the arguments must be addresses (&x, &y).
Fill all three blanks to create a function that increments an integer value using a pointer.
func increment([1] [2]int) { *[3] += 1 } var num int = 7 increment(&num) fmt.Println(num)
The function parameter is a pointer named p of type *int. Inside, dereference p with *p to increment the value.