1 parent 37d5ac9 commit a38a043Copy full SHA for a38a043
8_arrays/arrays.go
@@ -0,0 +1,35 @@
1
+package main
2
+import "fmt"
3
+
4
+//ARRAYS -numbered sequence of specific length
5
+func main(){
6
7
+ var nums [5]int //declare
8
9
+ fmt.Println(len(nums)) //to get length
10
11
+ nums[0] = 1 //insert
12
+ fmt.Println(nums[0]) //get number at any index
13
14
+ fmt.Println(nums) //print whole array //OUTPUT-[1 0 0 0]
15
16
17
+ var vals[4]bool
18
+ fmt.Println(vals) //output- [false false false false]
19
20
21
+ nums:=[3]int{4,5,6} //to declare in single line
22
+ fmt.Println(nums)
23
24
25
+ //2D Arrays
26
+ nums:=[2][2]int{{3,4},{5,6}}
27
28
29
30
+}
31
32
33
+//-fixed size,tht is predictable
34
+//-memory optimization
35
+//-constant time access
0 commit comments