• A Datatype whose value is Memory Address, and itself is located at a memory address too
  • In the diagram below shows some Go codes, we create a pointer var p *int32 = new(int32) and perform Pointer Dereference with *p

Pass data by pointer

Pass data to functions by pointer is memory-efficient. The data we pass into a function is basically a Memory Address to access that block of data. If we pass data into functions without pointer. We need to create an entire duplicate of data and pass it to the functions.

In Java, data is passed to functions by pointer by default. However in Go, we need to explicity specify the pointer datatype for the function input, then we can pass data by point!


Pointer Dereference

Null Pointer

  • Pointer that doesn’t point to any memory location, basically contains a invalid Memory Address
  • In C, it is represented by 0 or nullptr
  • In Java, it is represented by null, Custom Datatype can be null
  • In Go, it is represented with nil

Void Pointer

  • A Pointer without Datatype aka a pre-defined size
  • Used when we aren’t sure what the exact size of a variable like the return type of malloc
  • We should always try to cast it to a specific type whenever it is possible


Rust Box

Rust References

  • Non-owning pointers that points to Rust Box, thus they do not own the data they point to.
  • Powers Rust Borrowing