Golang's pointer (point) to explore

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Record Code First

Package Mainimport"FMT"/*declaring pointer *t is the type of a pointer variable that points to the value of type T*/Func Main () {//B: = 255//var a *int = &b//A is the int pointer, and the memory address to B//FMT. Printf ("Type of Is:%t\n", a)//FMT. PRINTLN ("Address of B is", a)//    //A: =//var b *int//b This variable is a pointer variable of type int, the value of the variable, and only the int type pointer//if b = = Nil {//    //the 0 value of the pointer is nil//FMT. Println ("B is", b)//B = &a//FMT. Println ("B after initialization is", B)//}    //B: = 255//A: = &b//FMT. PRINTLN ("Address of B is", a)//Print B's memory address//FMT. Println ("value of B is", *a)//prints the value of B, which can be obtained by *a the pointer//B: = 255//A: = &b//FMT. PRINTLN ("Address of B is:", a)//memory address of B//FMT. Println ("Value of B is:", *a)//*a++//with a pointer plus a//FMT. PRINTLN ("New value of B is:", b)//A: = +/ -//FMT. Println ("Value of a befor func call is:", a)//B: = &a//Change (b)//pointer variable b, change the value of a, a=55,//FMT. Println ("Value of a after call is:", a)    /*do not pass pointers to arrays as arguments to functions, use slices instead*/    //A: = [3]int{89, A.//Modify (&a)//Pass the address of array A, to modify//FMT. Println (a)A:= [3]int{ the, -, the} modify (a[:])//Pass in a slice of aFMT. Println (a)}//The function passes the pointer, changing the memory address of the parameter. //func Change (val *int) {//*val =//Modifying the value of an array//passes a pointer to an array, as a parameter, and modifies it//func Modify (arr *[3]int) {//(*arr) [0] =//    //arr[0]=90//can also be written, this is the shorthand form above (*a) [X] can be written a[x]//}//slicing methods modifying functions//This method is the most common and best way to modify a function .... Func Modify (SLS []int) {sls[0] = the}//go does not support pointer arithmetic like C

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.