Junior — Senior
Determining the output values and size of a structure when passing it by pointer
livecode
Task condition
It is necessary to understand what data will be printed before calling the mutatePtr function, what the function itself will output, and how the values will change after its execution. Additionally, it is required to find out how many bytes the declared structure occupies in memory.
type st struct {
// 4 ??? sizeof
p1 bool
p2 int
p3 bool
}
// ptr
func main() {
myStr := st{}
fmt.Println(myStr) // 1 ???
mutatePtr(&myStr)
fmt.Println(myStr) // 3 ???
fmt.Println(unsafe.Sizeof(myStr))
}
func mutatePtr(in *st) {
in = &st{
p1: true,
p2: 666,
p3: false,
}
fmt.Println("in mutatePtr:", in) // 2
}