Question:

What is the difference, if any, in the following two slice declarations, and which one is more preferable?

var a []int

and

a := []int{}

Answer:

The first declaration does not allocate memory if the slice is not used, so this declaration method is preferred.


Keywords:

© 2017 QuizBucket.org