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
//or
i3 := &int(12)

No. Use

ip := new(int)
*ip = 12

Or

i := 12
ip := &i

The slice gymnastics are nasty.

2 Likes

Iā€™m just going to leave this here, might be helpful: https://www.youtube.com/watch?v=bmZNaUcwBt4

1 Like

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