Types
- basic
- number
- int octal begin with 0, hexadecimal 0x
- int8
- int16
- int32
- int64
- rune (int32) single quoted unicode character eg ‘a’
- uint
- uint8
- uint16
- uint32
- uint64
- uintptr
- byte (uint8)
- float32
- float64
- complex64
- complex128
0.867 + 0.5i
- int octal begin with 0, hexadecimal 0x
- string
- []byte
- bool
- number
- aggregate (composite, fixed size)
- arrays
[3]int{1,2,3}
- structs
ages.alice = 31
- arrays
- reference
- pointers
- slices
- maps
ages["alice"] = 31
- functions
- channels
- interface
pointers
Ampersands and Asterisks
Go uses the same notation as C for pointers where the memory address of a variable x
is &x
and if we store this memory address in p
then whatever is stored in that memory address is retrieved as *p
.
The unary operator & gives the address of an object
/*
Simple use of the & unary operator
*/
package main
import "fmt"
func main() {
s := "I know your address"
fmt.Printf("%v\n", &s)
}
Running that gives me 0xc000014080. This memory address is a value that can be stored in a variable to get used (or abused) in various ways. A variable containing a memory address is called a pointer.