Beginner Go (Golang)
Q16 / 100

How do you add a method to a struct?

Correct! Well done.

Incorrect.

The correct answer is B) Define a function with a receiver: func (p *Point) Scale(n int)

B

Correct Answer

Define a function with a receiver: func (p *Point) Scale(n int)

Explanation

func (p Point) String() string { ... } or func (p *Point) Scale(n int) { p.X *= n } define methods. Pointer receivers allow mutation.

Progress
16/100