Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Go pointers

Shulou Source: shulou.com Published: 2022-06-01 02:31:33 09月21日 Update

In this article, Xiaobian introduces "how to use Go pointer" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use Go pointer" can help you solve your doubts.

How to use pointers

Pointer usage process:

Define pointer variables.

Assign a value to the pointer variable.

Access the value in the pointer variable that points to the address.

Precede the pointer type with a * (prefix) to get what the pointer points to.

Example

Package main

Import "fmt"

Func main () {

Var an int= 20 / * declare the actual variable * /

Var ip * int / * declare pointer variable * /

Ip = & a / * Storage address of pointer variable * /

Fmt.Printf (the address of "a variable is:% x\ n", & a)

/ * Storage address of pointer variable * /

Fmt.Printf ("pointer address stored by the ip variable:% x\ n", ip)

/ * use pointers to access values * /

Fmt.Printf ("* ip variable value:% d\ n", * ip)

}

The output of the above example is as follows:

A variable address is: 20818a220ip variable storage pointer address: 20818a220*ip variable value: 20 read here, this "how to use Go pointer" article has been introduced, want to master the knowledge of this article also need to practice to understand, if you want to know more about the content of the article, welcome to follow the industry information channel.

Tags: Pointers variables addresses content articles instances pointing storage proper prefixes actual ideas new knowledge more steps processes knowledge knowledge points articles types Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple vpn Shulou Tech Info Docker