create a pointer to a rune in go

In Go, a rune is an alias for the int32 type and represents a Unicode code point. To create a pointer to a rune in Go, you can define a variable of type rune and use the & operator to get its memory address. Here's an example:

main.go
package main

import "fmt"

func main() {
    var r rune = 'あ'
    pR := &r
    fmt.Printf("r: %c, address: %v\n", r, pR)
}
124 chars
10 lines

In this example, we first define a variable r of type rune and assign it the Unicode character 'あ' (which has the code point U+3042). We then use the & operator to get the memory address of r and assign it to the variable pR, which has type *rune (i.e., a pointer to a rune). Finally, we print the value and memory address of r using the fmt.Printf function and the %c and %v format specifiers, respectively.

Output:

main.go
r: あ, address: 0x1040a124
26 chars
2 lines

related categories

gistlibby LogSnag