inspectSlice exposes the slice header for review. Parameter: again, there is no value in side the []string so we want a slice. Range over a slice, just like we did with array. While len tells us the length, cap tells us the capacity In the output, we can see the addresses are aligning as expected.
(slice []string)
| 281 | // While len tells us the length, cap tells us the capacity |
| 282 | // In the output, we can see the addresses are aligning as expected. |
| 283 | func inspectSlice(slice []string) { |
| 284 | fmt.Printf("Length[%d] Capacity[%d]\n", len(slice), cap(slice)) |
| 285 | for i := range slice { |
| 286 | fmt.Printf("[%d] %p %s\n", i, &slice[i], slice[i]) |
| 287 | } |
| 288 | } |