Data Type - Pointer (Locator)

1 - About

A pointer is the address location at which a value is stored.

The pointer is a value that refers directly to (or “points to”) another value stored elsewhere in the computer memory using its address.

A pointer value is the address of a variable. Not every value has an address, but every variable does. With a pointer, we can read or update the value of a variable indirectly, without using or even knowing the name of the variable, if indeed it has a name.

  • A pointer references a location in memory.
  • Obtaining the value at the location a pointer refers to is known as dereferencing the pointer.
  • A pointer is a simple, less abstracted implementation of the more abstracted reference data type.
  • Pointers are also used to hold the addresses of entry points for called subroutines in procedural programming and for run-time linking to dynamic libraries.
  • In Object-oriented programming, pointers to functions are used for binding methods, often using what are called virtual method tables.

In some languages, notably C, pointers are relatively unconstrained. In other languages, pointers are disguised as references and there’s not much that can be done with them except pass them around.

3 - Performance

Pointers to data significantly improve performance for repetitive operations such as:

  • traversing strings,
  • lookup tables,
  • control tables
  • and tree structures.

In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point.

4 - Arithmetic - Data structures

While “pointer” has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated (arithmetically via pointer arithmetic) as a memory address, as opposed to a magic cookie or capability where this is not possible.

Pointers aren't necessary for the creation of complex data structures and algorithms. In fact, eliminating pointers makes such code not only easier to write and to understand but more secure and less prone to error as well.

5 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap