Reassigning in pointer method receiver

In the first example:

func (s *student) update() {
    s = &student{"unknown", 0}
}

You are assigning an entirely new “pointer value” to s, and the new *s points at a new student value. The variable s is scoped only to the method body, so there are no side effects after this returns.

In the second example

func (s *student) update() {
    *s = student{"unknown", 0}
}

You are dereferencing s, and changing the value of *s to point to a new student value, or to put it differently, you are putting a new student value at the address where s points.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)