My code snippet
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
fmt.Println("check 1: ",s, len(s))
s = s[1:4]
fmt.Println("check 2: ",s, len(s))
s = s[3:5]
fmt.Println("check 3: ",s, len(s))
s = s[1:]
fmt.Println("check 4: ",s, len(s))
}
Output
check 1: [2 3 5 7 11 13] 6
check 2: [3 5 7] 3
check 3: [11 13] 2
check 4: [13] 1
My Expected Output
check 1: [2 3 5 7 11 13] 6
check 2: [3 5 7] 3
panic: runtime error: slice bounds out of range [3:5]
s = s[1:4]
- Here we updated slice variable s which now contains [3 5 7] and s = s[3:5]
should give out of range error
since the index 3 to 5 doesn't exist in the new value of s
Instead, why did the output print - [11 13]