Pointers

If you pass structs or variables to a function, it makes a copy of them. By using a pointer it avoids making a copy and the value can directly be mutated.

Example:

outputUserDetails(&appUser)

}

func outputUserDetails(u *user) {
	fmt.Println(u.firstName, u.lastName, u.birthdate, u.createdAt)
}

Why it might be useful and when to use:

Last updated