Passing by pointers

Report a typo

Patrick has created a Go program that takes as input his old favorite rapper firstName and lastName and then uses the function updateRapper to update the name of his favorite rapper within his Go program. However, when he tried to execute his program, his function couldn't update the values of the variables firstName and lastName.

Can you help Patrick fix the updateRapper function? He needs the function to specifically update firstName to Mac and lastName to Miller, as Mac Miller is his new favorite rapper.

Take notice that to solve this task, it is not necessary to change any code within the main function; the objective is to fix the updateRapper function as it has errors in both the parameter type declaration and in the type of the variables used within it as well!

Sample Input 1:

Kendrick Lamar

Sample Output 1:

My favorite rapper was: Kendrick Lamar
My new favorite rapper is: Mac Miller
Write a program in Go
package main

import "fmt"

// Change the 'updateRapper' function type of parameters and the type of variables within it:
func updateRapper(fName string, lName string) {
fName = "Mac" // do not change the name!
lName = "Miller" // do not change the last name!
}

func main() {
// DO NOT delete! -- This code block takes as an input the name/last name of the rapper
var firstName, lastName string
fmt.Scanln(&firstName, &lastName)

fmt.Println("My favorite rapper was:", firstName, lastName)

updateRapper(&firstName, &lastName)

fmt.Println("My new favorite rapper is:", firstName, lastName)
}
___

Create a free account to access the full topic