title: Initialize pointer array - cannot make type *[]type
body: <p>Its a simple code, saving <code>car</code> type objects into a <code>car</code> type array. I am trying to use pointer here to pass array reference.</p>
  
  <p><strong>There are 2 problems:</strong></p>
  
  <p><strong>1</strong> - I can't initialize it as empty array. When I use <code>make</code>, it says:</p>
  
  <blockquote>
    <p>cannot make type *[]car</p>
  </blockquote>
  
  <p><strong>2</strong> - If I don't use <code>make</code>, runtime error occurs:</p>
  
  <blockquote>
    <p>panic: runtime error: invalid memory address or nil pointer dereference</p>
  </blockquote>
  
  <hr>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import "fmt"
  
  type car struct {
      plate string
      color string
  }
  
  func main() {
  
      var _cars *[]car        // list of cars
      _cars = make(*[]car, 4) // initialize empty cars list
  
      saveCar(_cars, car{"ABC-123", "Black"})
      saveCar(_cars, car{"ABC-456", "Black"})
      saveCar(_cars, car{"ABC-789", "Black"})
  
      fmt.Println(_cars)
  }
  
  func saveCar(_cars_list *[]car, _car car) int {
  
      for index, current := range *_cars_list {
          // if empty place found, save car
          if (car{}) == current {
  
              // save car
              (*_cars_list)[index] = _car
  
              // return the saved index
              return index
          }
      }
  
      return -1
  }
  </code></pre>