How to instantiate struct using new keyword in Go

1 Answer

0 votes
package main
 
import "fmt"
 
type S struct {
	n  int
	s string
}
 
func main() {
	st := new(S) 
	
	st.n = 848
	st.s = "go"

	fmt.Println(st)
	
	fmt.Println(st.n)
	fmt.Println(st.s)
}




/*
run:

&{848 go}
848
go

*/

 



answered Aug 24, 2020 by avibootz

Related questions

1 answer 259 views
259 views asked Aug 23, 2020 by avibootz
1 answer 289 views
1 answer 268 views
268 views asked Aug 24, 2020 by avibootz
1 answer 318 views
2 answers 379 views
379 views asked Aug 9, 2020 by avibootz
3 answers 444 views
...