On Thu, Mar 7, 2019 at 8:31 AM <halbert.coll...@gmail.com> wrote: > > Hi. > > The code like below: > > package main > > import "fmt" > > func main() { > primes := [6]int{2, 3, 5, 7, 11, 13} > fmt.Println(primes[6:6]) . // OK. return: [] > //fmt.Println(primes[6]) . // fail. out of bounds... > } > > Why?
Those two expressions are doing different things: primes[6:6] is a slice that begins after the last element of primes, with len=0. You can, for instance, add a new element to primes[6:6], which makes a new slice with one element. primes[6:7], for instance, would be an error, primes[6] is an int, accessing the element beyond array bounds, so it is an error. > > Is the golang grammatical feature? or anything else.. > > Any help, please! > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.