a:=[]int{10, 20}
fmt.Println(a)
and
a:=[...]int{10, 20}
fmt.Println(a)
Both work and give the same output
Is there any difference between them?
a:=[]int{10, 20}
fmt.Println(a)
and
a:=[...]int{10, 20}
fmt.Println(a)
Both work and give the same output
Is there any difference between them?
Yes. [] creates a growable slice while [...] will create a fixed size array.
I’m new to Go, could you please clarify with an example…
I’m also new. But in the second case, you can’t just add a new element to the array
a=append(a,11)
fmt.Println(a)
Read below about slices and fixed size arrays.