Monthly Archives: June 2020
I have recently enrolled on a Udemy course called GetGoing: Introduction to Golang as I wanted to sink my teeth into the marvellous world of Go; its simplicity and its power to harness concurrency. One of the first concepts you are likely to get confused about when starting to learn Go is the use of the two operators & and
& is placed in front of a variable and returns its memory address
myVariable := "aBeautifulString"
The result is a memory address, in this fashion:
* (aka reference operator) is placed in front of a variable that holds a memory address and resolves it. For example:
aString := "thisIsAString"
anotherString := *&aString
The result will be
There is also an additional case where the operator
* is placed in front of a type, e.g.
*string and it becomes part of the type declaration stating that the variable holds a pointer to a string. For example:
var str *string