March 2019
Intermediate to advanced
336 pages
9h 9m
English
The main method initializes the variable number to 17. The pointer to the number is passed to the addOne function. The number value and address is printed before and after invoking the addOne function.
In this example, the address of the number is the same as the value of num in the addOne function. Pointers share the address of the variable for the function to access for reads and writes within the stack frame. Pointer types are specific to every type that is declared. Pointers provide indirect memory access outside the function's stack frame. This is shown in the following code:
// main methodfunc main() { var number int number = 17 fmt.Println("value of number", number, "Address of number", &number) addOne(&number) fmt.Println("value ...Read now
Unlock full access