Posts

Showing posts with the label maps

Advanced Data Types in Go

Image
Introduction In my previous blog , I discussed the basic data types in Go. In this blog, we will be going a step ahead and learning about advanced data types in GO. We will be talking about Arrays Slices Maps Structs Arrays Arrays as in other traditional languages are a collection of variables of homogeneous types i.e means instead of creating 10 variables to store same type of data let's say marks we create an array that can store 10 elements. Some of the key points about arrays in Go are: Arrays in Go are fixed size Array index starts from 0 Same type of data can be stored in an array Data Type has to be given while the array declaration The syntax for array declaration: //Array declaration var arr [3]int //Indexing the array arr[0]=1 arr[1]=2 arr[2]=3 We can also use shorthand notation for the Arrays //Array declaration and initialization arr1 := [3]int{1, 2, 3} Slices Slices, on the other hand, is a data structure more flexib