Created
March 9, 2015 14:28
-
-
Save ernestas-poskus/db3880e4f9d1146cf4ca to your computer and use it in GitHub Desktop.
Go pointer overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// & (overloaded) - bitwise, address of operator, memory address | |
// * (indirection, dereference, type modifier) - access to value pointed by the variable | |
func main() { | |
var pi *int | |
z := 37 // z is of type int | |
pi = &z // pi is of type *int (pointer to int) | |
ppi := &pi // ppt is o type **int (pointer to pointer to int) | |
// Sematically same as: **ppi++, (*(*ppi))++ and *(*ppi)++ | |
fmt.Println(z, *pi, **ppi) | |
**ppi++ | |
fmt.Println(z, *pi, **ppi) | |
(*(*ppi))++ | |
fmt.Println(z, *pi, **ppi) | |
*(*ppi)++ | |
fmt.Println(z, *pi, **ppi) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment