I have the following code:
type box struct {
val int
}
var p *box
This works fine:
p = &box{val: 2}
But this results in error:
*p = box{val: 2}
Error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5e59d9]
Why does the 2nd form of assignment result in panic?