One line pointer literal initialzation

Is one of these below the best one line way to initialize the value of a pointer variable

var i0 *int = &[]int{300}[0]
i1 := &[]int{200}[0]

Or is there something simpler. Ideally I would like something like this:

var i2 *int = 12
i3 := &int(12)

No. Use

ip := new(int)
*ip = 12


i := 12
ip := &i

The slice gymnastics are nasty.


Iā€™m just going to leave this here, might be helpful:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.