Programming Languages - Pointers
Pointers
A pointer holds the memory address of a value.
Smart pointers are data structures that have additional metadata and functionalities.
Go
The type *T is a pointer to a T value. Its zero value is nil.
The & operator generates a pointer to its operand.
i := 42
p = &i
The * operator denotes the pointer's underlying value.
fmt.Println(*p) // read i through the pointer p
*p = 21 // set i through the pointer p
Unlike C, Go has no pointer arithmetic.
Pointers to structs
If p is a pointer to a struct, We can use p.X to access field X instead of (*p).X:
v := Vertex{1, 2}
p := &v
p.X = 1e9
Recommended ReadingSponsored
Concepts
Overview
Which Programming Languages To Learn
Compile Time and Runtime
Standard Libraries
Build Tools
Memory Management
Zero Cost Abstractions
Design Patterns
Constructors
Compatibility
Closures
Functional Programming
Generics
String Interning
Coding Conventions
Main
Ranges
Lambda
Random
IO
Operators
Built-in
Constants
Functions
Generics
Print
Pointers
Annotations
Quotes
Destructuring
Generators
Imports
Iterators
Testing
Visibility
Assignment Semantics
Slices
SSA
Versus
Concurrency
Control Flow
Data Structures

