github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/type33.gno (about) 1 package main 2 3 import "fmt" 4 5 // Define a base type 6 type Base int 7 8 // Declare a new type that is a pointer to the base type 9 type PtrToBase *Base 10 11 func main() { 12 var b Base = 42 // Initialize a variable of the base type 13 var p PtrToBase = &b // Initialize a variable of the new pointer type with the address of b 14 15 fmt.Printf("The value of b is: %d\n", b) 16 17 // Using the new pointer type 18 fmt.Printf("The value pointed to by p is: %d\n", *p) 19 20 // Modifying the value pointed to by p 21 *p = 100 22 fmt.Printf("The new value of b after modification through p is: %d\n", b) 23 } 24 25 // Output: 26 // The value of b is: 42 27 // The value pointed to by p is: 42 28 // The new value of b after modification through p is: 100