title: Pointer value set to zero after being changed in a struct method
body: <p>Here is my code:</p>
  <pre><code>type Cake struct {
      weight      int
      value       int
      costBenefit float32
  }
  
  func (c *Cake) SetCostBenefit() float32 {
      if c.costBenefit == 0 {
          c.costBenefit = float32(c.value) / float32(c.weight)
      }
  
      return c.costBenefit
  }
  
  func main() {
      capacity := 20
      cakes := []Cake{{weight: 7, value: 160}, {weight: 3, value: 90}, {weight: 2, value: 15}}
  
      result := maxDuffelBagValue(cakes, capacity)
      fmt.Printf(&quot;Max capacity %d&quot;, result)
  }
  
  func maxDuffelBagValue(cakes []Cake, capacity int) int {
      calcCostBenefit(&amp;cakes)
  
      for _, c := range cakes {
          fmt.Printf(&quot;Value Cake cost benefit 2: %v \n&quot;, c.costBenefit)
      }
  
      return 0
  }
  
  func calcCostBenefit(cakes *[]Cake) {
      for _, c := range *cakes {
          c.SetCostBenefit()
          fmt.Printf(&quot;Value Cake cost benefit 1: %v \n&quot;, c.costBenefit)
      }
  }
  
  </code></pre>
  <p>As you can see above, I have a struct method that sets the <em>CostBenefit</em> property of the struct <em>Cake</em>. As I'm sending the array of cakes to the method <em>calcCostBenefit</em>, any change within the method should reflect the array in the outside (caller method). But actually, it doesn't happen. Here's the output:</p>
  <pre><code>Value Cake cost benefit 1: 22.857143
  Value Cake cost benefit 1: 30
  Value Cake cost benefit 1: 7.5
  Value Cake cost benefit 2: 0
  Value Cake cost benefit 2: 0
  Value Cake cost benefit 2: 0 
  </code></pre>
  <p>The values get reset to zero and I don't know why. I've tried several changes in the code, but nothing worked. What am I missing here? It's driving me crazy nothing being able to spot something that might be so obvious and simple.</p>