Advertisement
cwchen

[Go] Declaring a pointer to an integer.

Sep 27th, 2017
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.28 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "log"
  6. )
  7.  
  8. func main() {
  9.     n := 2
  10.  
  11.     // Reference the adress from the variable.
  12.     nPtr := &n
  13.  
  14.     // Print out the address.
  15.     fmt.Println(nPtr)
  16.  
  17.     // Dereference the pointer to get the value.
  18.     if !(*nPtr == 2) {
  19.         log.Fatal("Wrong value")
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement