I am doing some experiments on the slice, When i assign value to a slice with in the length range, it worked fine But when i assign value to a slice with in the cap range without append() func, it gave me runtime error.
Eg: mySlice := make([]int, 3, 5) mySlice[3] = 4 // runtime error
If capacity in make function means, the total space already been allocated for the slice. Then, why i am not able to access that location with indexing?? Why only we can store values using append() func only, if we want to assign value more than length range specified but in the cap range??
package main
import "fmt"
func main() {
mySlice := make([]int, 3, 5)
mySlice[0] = 1
mySlice[1] = 2
mySlice[2] = 3
mySlice[3] = 4 `This giving me error saying that "index out of range [3] with length 3"`
fmt.Println("mySlice....", mySlice)
}