Go Slices: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 12: | Line 12: | ||
=Declaration= | =Declaration= | ||
A slice declaration is similar to an array's except the length is not specified. | A slice declaration is similar to an array's except the length is not specified. The slice is created with a zero length. | ||
<pre> | <pre> | ||
var s []int | var s []int | ||
</pre> | |||
Type inferred declaration: | |||
<pre> | |||
s := make([]int, 5) | |||
</pre> | </pre> | ||
Revision as of 23:18, 27 March 2016
Internal
Overview
A slice is a reference type that implements a dynamic array. Slices are indexable, and they have a variable length.
TODO Deep difference between slice and array (memory model, etc.)
Declaration
A slice declaration is similar to an array's except the length is not specified. The slice is created with a zero length.
var s []int
Type inferred declaration:
s := make([]int, 5)