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 170 views
170 views asked Aug 23, 2020 by avibootz
1 answer 198 views
1 answer 164 views
164 views asked Aug 24, 2020 by avibootz
1 answer 219 views
2 answers 240 views
240 views asked Aug 9, 2020 by avibootz
3 answers 271 views
1 answer 155 views
...