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 268 views
268 views asked Aug 24, 2020 by avibootz
1 answer 294 views
4 answers 534 views
1 answer 289 views
2 answers 378 views
378 views asked Aug 9, 2020 by avibootz
1 answer 286 views
286 views asked Mar 7, 2020 by avibootz
6 answers 859 views
859 views asked Feb 25, 2020 by avibootz
...