...

/

Array Literals and Parameters

Array Literals and Parameters

This lesson explains array literals and handling arrays as parameters to functions in detail.

Array literals

When the values (or some of them) of the items are known beforehand, a simpler initialization exists using the { , ,} notation called array literals (or constructors) instead of initializing every item in the [ ]= way. Let’s see some variants.

1st variant

Specify explicitly the size n of the array with [n]. For example:

var arrAge = [5]int{18, 20, 15, 22, 16}

Here is another example:

 ...