Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

see_its_a_new_array

package main

import "fmt"

func main() {
    x := &[10]int{1,2,3,4,5,6,7,8,9,10}
    y := x[2:5]
    z := y[:1:2]
    
    fmt.Printf("cap %v, array: %v\ncap y: %v, slice: %v\ncap z: %v, slice: %v\n", cap(x) , *x, cap(y), y, cap(z), z)
    z = append(z, 0, 0, 0, 0, 0)
    fmt.Printf("cap %v, array: %v\ncap y: %v, slice: %v\ncap z: %v, slice: %v\n", cap(x) , *x, cap(y), y, cap(z), z)
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.