notexOPENOverview
Notex/Languages/Code Review: Intro to pointers, new, and shallow copies
04.04LESSON 04 OF 20 · 1 MIN READ

Code Review: Intro to pointers, new, and shallow copies

Always free to read
  • Structs and primitive types in Go can be either pointers or values. In many other languages, primitive types are always values and classes are always pointers.

  • Use new to make a pointer out of a constant or literal value, or to make a non-nil pointer to an instance of a type.

  • When a variable is passed to new, it makes a pointer to a shallow copy of the variable. Pointer fields in the copy still alias the original’s data. Use & when you mean to reference the original, not duplicate it.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K