Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to use pointer to int in Go

3 Answers

0 votes
package main
 
import (
    "fmt"
)
 
func main() {
    var p *int
    
    p = new(int)
    
    *p = 8297
    
    fmt.Printf("%p\n", p)
    fmt.Printf("%v\n", *p)
}



/*
run:

0xc000090010
8297

*/

 



answered Aug 15, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
)
 
func main() {
    i := int(893)
    fmt.Printf("i=  %T: &i=%p  i=%v\n", i, &i, i)
    
    p := &i
    fmt.Printf("p= %T:  p=%p *p=%v &p=%p\n", p, p, *p, &p)
}



/*
run:

i=  int: &i=0xc000016068  i=893
p= *int:  p=0xc000016068 *p=893 &p=0xc00000e030

*/

 



answered Aug 15, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
)
 
func main() {
    var p *int
    
    i := int(893)
    fmt.Printf("i=  %T: &i=%p  i=%v\n", i, &i, i)
    
    p = &i
    fmt.Printf("p= %T:  p=%p *p=%v &p=%p\n", p, p, *p, &p)
}



/*
run:

i=  int: &i=0xc000098010  i=893
p= *int:  p=0xc000098010 *p=893 &p=0xc00009a018

*/

 



answered Aug 15, 2020 by avibootz

Related questions

1 answer 182 views
1 answer 155 views
155 views asked Mar 7, 2020 by avibootz
1 answer 161 views
161 views asked Aug 15, 2020 by avibootz
3 answers 243 views
2 answers 215 views
1 answer 179 views
179 views asked Aug 26, 2020 by avibootz
...