Lably
Skip to content

Reference (computer science)

Data type which allows a program to indirectly access a particular value in memory

  • 8 min read
  • 5 chapters

Learn it on Lably

A reference is an abstract data type and may be implemented in many ways. Typically, a reference refers to data stored in memory on a given system, and its internal value is the memory address of the data, i.e. a reference is implemented as a pointer. For this reason a reference is often said to "point to" the data. Other implementations include an offset (difference) between the datum's address and some fixed "base" address, an index, or identifier used in a lookup operation into an array or table, an operating system handle, a physical address on a storage device, or a network address such as a URL.

Formal representation

A reference R is a value that admits one operation, dereference(R), which yields a value. Usually the reference is typed so that it returns values of a specific type, e.g.:

<span id="mwLw"></span><span class="kd" id="mwMA">interface</span> <span class="nc" id="mwMQ">Reference</span><span class="o" id="mwMg"><</span><span class="n" id="mwMw">T</span><span class="o" id="mwNA">></span><span class="w" id="mwNQ"> </span><span class="p" id="mwNg">{</span> <span class="w" id="mwNw"> </span><span class="n" id="mwOA">T</span><span class="w" id="mwOQ"> </span><span class="nf" id="mwOg">value</span><span class="p" id="mwOw">();</span> <span class="p" id="mwPA">}</span>

Often the reference also admits an assignment operation store(R, x), meaning it is an abstract variable.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication