<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="default.xsl"?>
<fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="true"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>380</fr:anchor><fr:addr
type="user">go-00s5</fr:addr><fr:route>go-00s5.xml</fr:route><fr:title
text="Golang › Slices › Slicing"><fr:link
type="local"
href="go-00s0.xml"
addr="go-00s0"
title="Golang › Slices"><fr:link
type="local"
href="go-00rs.xml"
addr="go-00rs"
title="Golang">Golang</fr:link> › Slices</fr:link> › Slicing</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[s[low:high]     // items low through high-1
s[low:]         // items low through end
s[:high]        // items beginning through high-1
s[:]            // copy of entire slice
s[low:high:max] // control capacity of new slice]]></fr:pre></fr:mainmatter><fr:backmatter><fr:tree
toc="false"
numbered="false"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:title
text="Context">Context</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:tree
toc="true"
numbered="false"
show-heading="true"
show-metadata="true"
expanded="false"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>381</fr:anchor><fr:addr
type="user">go-00s0</fr:addr><fr:route>go-00s0.xml</fr:route><fr:title
text="Golang › Slices"><fr:link
type="local"
href="go-00rs.xml"
addr="go-00rs"
title="Golang">Golang</fr:link> › Slices</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:ul><fr:li>Slices will have a zero value of <fr:code>nil</fr:code> and is only comprable with <fr:code>nil</fr:code> and <fr:code>==</fr:code>.</fr:li>
    <fr:li>Modifying shared slices will affect all references.</fr:li>
    <fr:li>Length can differ from capacity</fr:li></fr:ul><fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>267</fr:anchor><fr:addr
type="user">go-00s3</fr:addr><fr:route>go-00s3.xml</fr:route><fr:title
text="Creation">Creation</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[var s []int             // nil slice
s := []int{1, 2, 3}     // slice literal
s := make([]int, 5)     // length 5, capacity 5
s := make([]int, 0, 10) // length 0, capacity 10]]></fr:pre></fr:mainmatter><fr:backmatter /></fr:tree><fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>268</fr:anchor><fr:addr
type="user">go-00s4</fr:addr><fr:route>go-00s4.xml</fr:route><fr:title
text="Modification">Modification</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[s = append(s, 10)           // single element
s = append(s, 1, 2, 3)      // multiple elements
s = append(s, other...)     // append slice
clear(s)                    // zero all elements (Go 1.21+)]]></fr:pre></fr:mainmatter><fr:backmatter /></fr:tree><fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>269</fr:anchor><fr:addr
type="user">go-00s5</fr:addr><fr:route>go-00s5.xml</fr:route><fr:title
text="Slicing">Slicing</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[s[low:high]     // items low through high-1
s[low:]         // items low through end
s[:high]        // items beginning through high-1
s[:]            // copy of entire slice
s[low:high:max] // control capacity of new slice]]></fr:pre></fr:mainmatter><fr:backmatter /></fr:tree><fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>270</fr:anchor><fr:addr
type="user">go-00s6</fr:addr><fr:route>go-00s6.xml</fr:route><fr:title
text="Copying">Copying</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[copy(dest, src)        // copies min(len(dest), len(src)) elements
copy(dest, src[1:])    // copy from middle of src]]></fr:pre></fr:mainmatter><fr:backmatter /></fr:tree><fr:tree
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"><fr:frontmatter><fr:anchor>271</fr:anchor><fr:addr
type="user">go-00s7</fr:addr><fr:route>go-00s7.xml</fr:route><fr:title
text="Array Conversion">Array Conversion</fr:title><fr:authors /></fr:frontmatter><fr:mainmatter><fr:pre><![CDATA[array := [4]int{1, 2, 3, 4}
slice := array[:]              // array to slice
array2 := [4]int(slice)       // slice to array (new memory)
arrayPtr := (*[4]int)(slice)  // slice to array pointer (shared memory)]]></fr:pre></fr:mainmatter><fr:backmatter /></fr:tree></fr:mainmatter><fr:backmatter /></fr:tree></fr:mainmatter><fr:backmatter /></fr:tree></fr:backmatter></fr:tree>