-
Notifications
You must be signed in to change notification settings - Fork 13
/
day14.4.go
28 lines (22 loc) · 917 Bytes
/
day14.4.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Using make() function
/*
You can also create a slice using the make() function
which is provided by the go library. This function takes
three parameters, i.e, type, length, and capacity.
It assigns an underlying array with a size that is equal
to the given capacity and returns a slice which refers to the
underlying array. Generally, make() function is used to create an
empty slice. Here, empty slices are those slices that contain an empty array reference.
*/
package main
import "fmt"
func main() {
// Creating an array and Using make() function
var my_slice_1 = make([]int, 4, 7)
fmt.Printf("Slice 1 = %v, \nlength = %d, \ncapacity = %d\n",
my_slice_1, len(my_slice_1), cap(my_slice_1))
// Creating another array and Using make function
var my_slice_2 = make([]int, 7)
fmt.Printf("Slice 2 = %v, \nlength = %d, \ncapacity = %d\n",
my_slice_2, len(my_slice_2), cap(my_slice_2))
}