GOLANG
Pointers in Go
A pointer is a variable that stores the memory address data referenced by another variable. Pointers have the power to mutate data they are pointing to.
Before we begin talking about pointers, let’s learn a thing or two about hexadecimal
numbers. A hexadecimal number is a number with base 16
. If you are a web developer, then you are using them for a long time, because mostly; colors are represented in hex format. For example, white is represented as #FFFFFF
and black as #000000
.
In Go, you can save a hexadecimal number in a variable and Go provides a literal expression for that. If a number starts with 0x
then it’s a hexadecimal number.
From the above example, we can see that values represented in the hexadecimal system are saved in the decimal system with data type int
.
But why we are learning about hexadecimal numbers when we are talking about pointers. Well, let’s talk about the memory address first.
When you are declaring a variable and providing some value (data), the Go runtime will allocate some memory for…