Significance of Go — Part 4 (Arrays, Slices, Maps and Structs)

Arrays

If you have not initialized an array the default values will be zeros.

Default values are initialized as zero values
Finding the length of an array

Use […] instead of length if the length of the array should be decided by the number of elements in the array automatically.

Use […] when declaring the array

Can compare two arrays using == operator.

Comparing two arrays
Error when you try to compare different type of arrays

Slices

A slice on top of an array

A slice on top of an array
Relationship between the slice and the array
  • In line 12, we have changed the first element of arr1 to 100.
  • In line 13, we have changed the last element of slice to 200.

A slice without an explicit underline array

A slice without an explicit underline array
append function with slices

Maps

Define a map and access the values

Structs

type book struct {
Title string
Sold bool
Pages int
}
Three ways to initialize a struct

Conclusion

Previous Articles

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Router Protocol Alpha Mainnet launch

XinFin Invites Users to Set-Up Masternode and Win Rewards.

Microservices with Spring Boot — Authentication with JWT and Spring Security

Beginning the Journey into IOS Development

How To Migrate Custom Fields To A Better Shopping Cart

Custom Fields Migration

How to run E2E tests on on-demand environments

Strategy design pattern in Python

How to Install LEMP on Ubuntu 19.04 and 18.04

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Wasura Wattearachchi

Wasura Wattearachchi

More from Medium

Introduction to gRPC

Testing the main of a golang http server

Testing in Golang(Part 1)— Unit Tests

Unit testing in go with MySQL