Created
June 24, 2019 10:06
-
-
Save victorsteven/1f57608ff63de166e8a5e9b6c3f76200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| //Function scope slice: | |
| //EXAMPLE 1: | |
| integerSlice := []int{10, 20, 30, 40, 50} | |
| stringSlice := []string{"first", "second", "third", "fourth"} | |
| fmt.Println("This is the integer slice: ", integerSlice) | |
| fmt.Println("This is the string slice: ", stringSlice) | |
| // EXAMPLE 2: | |
| // We can also define slice using the "make" builtin function | |
| s := make([]int, 4) | |
| s[0] = 10 | |
| s[1] = 20 | |
| s[2] = 30 | |
| s[3] = 40 | |
| fmt.Println("Slice created with 'make': ", s) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment