Created
March 3, 2015 11:47
-
-
Save sandeepraju/6bc234f5caa8c504398d to your computer and use it in GitHub Desktop.
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
// pointer dereference - differences | |
package main | |
import "fmt" | |
type User struct { | |
name string | |
email string | |
} | |
func (u *User) Print() { | |
fmt.Println(u.name, "-", u.email) | |
} | |
func main() { | |
// with custom type | |
user := new(User) // user is a pointer of type User | |
(*user).name = "Sandeep Raju" // this works cool. | |
user.email = "me@sandeepraju.in" // this works as well. | |
user.Print() | |
fmt.Println(user) | |
fmt.Println(*user) | |
fmt.Println(&user) | |
// with builtin types | |
x := new(int) | |
*x = 100 | |
fmt.Println(x) | |
fmt.Println(&x) | |
fmt.Println(*x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment