Skip to content

Commit 78996da

Browse files
committed
Adds appending into a slices eg
1 parent f2b7634 commit 78996da

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
7+
/**
8+
* Blank [] will declare a slices.
9+
* If you provide size like [5] will declare an array.
10+
*/
11+
var employee []string
12+
13+
/**
14+
* Initialize a slices with type, length and capacity.
15+
* length is required field.
16+
*
17+
* make([]string, length, [capacity])
18+
*/
19+
employee = make([]string, 3)
20+
21+
employee[0] = "Ashwin"
22+
employee[1] = "Kumar"
23+
employee[2] = "Saju"
24+
25+
fmt.Println("Slices: ", employee)
26+
27+
/**
28+
* Appending into slices.
29+
*/
30+
employee = append(employee, "Ajay")
31+
employee = append(employee, "Vinayak")
32+
33+
fmt.Println("After appending: ", employee)
34+
35+
}

0 commit comments

Comments
 (0)