Difference between []int and [...]int

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.

3 Likes

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)
1 Like

Read below about slices and fixed size arrays.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.