How to use nested anonymous struct (struct inside struct) in Go

1 Answer

0 votes
package main
 
import "fmt"
 
type A struct {
	n int
	s string
	B struct {
		c int
		d int
	}
}
 
func main() {
	var st A 
	
	st.n = 23
	st.s = "go"
 
	st.B.c = 876
	st.B.d = 93
 
	fmt.Println(st)
	
	fmt.Println(st.n)
	fmt.Println(st.B.c)

}



/*
run:

{23 go {876 93}}
23
876

*/

 



answered Aug 23, 2020 by avibootz

Related questions

1 answer 188 views
188 views asked Aug 24, 2020 by avibootz
1 answer 200 views
4 answers 291 views
1 answer 212 views
2 answers 259 views
259 views asked Aug 9, 2020 by avibootz
1 answer 186 views
186 views asked Mar 7, 2020 by avibootz
6 answers 585 views
585 views asked Feb 25, 2020 by avibootz
...