HOME

TheInfoList




In
computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , and . Computer science ...
, a pointer is an
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Entity, something that is tangible and within the grasp of the senses ** Object (abstract), an object which does not exist at any particular time or pl ...
in many
programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathematical structure, structure (algebra), space (geometry), and calcu ...

programming language
s that stores a
memory address In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwa ...
. This can be that of another value located in
computer memory In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
, or in some cases, that of memory-mapped
computer hardware Computer hardware includes the physical parts of a computer, such as the computer case, case, central processing unit (CPU), Computer monitor, monitor, Computer mouse, mouse, Computer keyboard, keyboard, computer data storage, graphics card, so ...

computer hardware
. A pointer ''references'' a location in memory, and obtaining the value stored at that location is known as '' dereferencing'' the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying
computer architecture In computer engineering Computer engineering (CoE or CpE) is a branch of engineering Engineering is the use of scientific method, scientific principles to design and build machines, structures, and other items, including bridges, tun ...
. Using pointers significantly improves
performance A performance is an act of staging or presenting a play, concert, or other form of entertainment. It is also defined as the action or process of carrying out or accomplishing an action, task, or function. Management science In the work place ...
for repetitive operations, like traversing iterable data
structures A structure is an arrangement and organization of interrelated elements in a material object or system A system is a group of Interaction, interacting or interrelated elements that act according to a set of rules to form a unified whole. A sy ...

structures
(e.g.
strings String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * Strings (1991 film), ''Strings'' (1991 fil ...
,
lookup table In computer science, a lookup table (LUT) is an array data structure, array that replaces runtime (program lifecycle phase), runtime computation with a simpler array indexing operation. The process is termed as "direct addressing" and LUTs differ fr ...
s,
control table Control tables are tables that control the control flow In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for the ...

control table
s and
tree In botany, a tree is a perennial plant with an elongated Plant stem, stem, or trunk (botany), trunk, supporting branches and leaves in most species. In some usages, the definition of a tree may be narrower, including only wood plants with se ...
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. Pointers are also used to hold the addresses of entry points for
call Call or Calls may refer to: Arts, entertainment, and media Games * Call, a type of betting in poker * Call, in the game of contract bridge, a bid, pass, double, or redouble in the bidding stage Music and dance * Call (band), from Lahore, Pakis ...
ed subroutines in
procedural programming Procedural programming is a programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with im ...
and for run-time linking to dynamic link libraries (DLLs). In
object-oriented programming Object-oriented programming (OOP) is a programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mai ...
, pointers to functions are used for binding methods, often using virtual method tables. A pointer is a simple, more concrete implementation of the more abstract ''
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
''
data type In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Alg ...
. Several languages, especially low-level languages, support some type of pointer, although some have more restrictions on their use than others. While "pointer" has been used to refer to references in general, it more properly applies to
data structures 315px, A data structure known as a hash table. In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of dat ...
whose
interface Interface or interfacing may refer to: Academic journals * Interface (journal), ''Interface'' (journal), by the Electrochemical Society * ''Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Lin ...
explicitly allows the pointer to be manipulated (arithmetically via ') as a memory address, as opposed to a
magic cookie In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and software ...
or
capability A capability is the ability to perform or achieve certain actions or outcomes. As it applies to human capital Human capital is the stock of habits, knowledge Knowledge is a familiarity, awareness, or understanding of someone or somethin ...
which does not allow such. Because pointers allow both protected and unprotected access to memory addresses, there are risks associated with using them, particularly in the latter case. Primitive pointers are often stored in a format similar to an
integer An integer (from the Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally spoken in the area around Rome, known as Latium. Through the power of the Roman Re ...
; however, attempting to dereference or "look up" such a pointer whose value is not a valid memory address could cause a program to crash (or contain invalid data). To alleviate this potential problem, as a matter of
type safety In computer science, type safety is the extent to which a programming language discourages or prevents type errors. A type error is erroneous program behaviour caused by a discrepancy between differing data types for the program's constants, variabl ...
, pointers are considered a separate type parameterized by the type of data they point to, even if the underlying representation is an integer. Other measures may also be taken (such as validation &
bounds checking In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, generati ...
), to verify that the pointer variable contains a value that is both a valid memory address and within the numerical range that the processor is capable of addressing.


History

In 1955, Soviet computer scientist
Kateryna Yushchenko Kateryna Mykhaylivna Yushchenko ( uk, Катерина Михайлівна Ющенко; née Chumachenko; September 1, 1961 in Chicago (''City in a Garden''); I Will , image_map = , map_caption = Interactive maps ...
invented the Address programming language that made possible indirect addressing and addresses of the highest rank – analogous to pointers. This language was widely used on the Soviet Union computers. However, it was unknown outside the Soviet Union and usually
Harold Lawson Harold W. "Bud" Lawson (1937–2019) was a software engineer, computer architect and systems engineer. Lawson is credited with the 1964 invention of the pointer (programming), pointer in high-level programming languages (with "a lot of comments" f ...
is credited with the invention, in 1964, of the pointer. In 2000, Lawson was presented the Computer Pioneer Award by the
IEEE The Institute of Electrical and Electronics Engineers (IEEE) is a professional association for electronic engineering and electrical engineering (and associated disciplines) with its corporate office in New York City and its operations center i ...
" r inventing the pointer variable and introducing this concept into PL/I, thus providing for the first time, the capability to flexibly treat linked lists in a general-purpose high-level language". His seminal paper on the concepts appeared in the June 1967 issue of CACM entitled: PL/I List Processing. According to the
Oxford English Dictionary The ''Oxford English Dictionary'' (''OED'') is the principal historical dictionary A historical dictionary or dictionary on historical principles is a dictionary which deals not only with the latterday meanings of words but also the historica ...
, the word ''pointer'' first appeared in print as a ''stack pointer'' in a technical memorandum by the
System Development Corporation System Development Corporation (SDC) was a computer software Software is a collection of Instruction (computer science), instructions and data (computing), data that tell a computer how to work. This is in contrast to Computer hardware, physic ...
.


Formal description

In
computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , and . Computer science ...
, a pointer is a kind of
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
. A ''data primitive'' (or just ''primitive'') is any datum that can be read from or written to
computer memory In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
using one memory access (for instance, both a ''
byte The byte is a unit of digital information that most commonly consists of eight bit The bit is a basic unit of information in computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It ...
'' and a ''
word In linguistics Linguistics is the scientific study of language A language is a structured system of communication used by humans, including speech (spoken language), gestures (Signed language, sign language) and writing. Most lang ...
'' are primitives). A ''data aggregate'' (or just ''aggregate'') is a group of primitives that are
logically Logic (from Ancient Greek, Greek: grc, wikt:λογική, λογική, label=none, lit=possessed of reason, intellectual, dialectical, argumentative, translit=logikḗ)Also related to (''logos''), "word, thought, idea, argument, account, re ...
contiguous in memory and that are viewed collectively as one datum (for instance, an aggregate could be 3 logically contiguous bytes, the values of which represent the 3 coordinates of a point in space). When an aggregate is entirely composed of the same type of primitive, the aggregate may be called an ''array''; in a sense, a multi-byte ''word'' primitive is an array of bytes, and some programs use words in this way. In the context of these definitions, a ''byte'' is the smallest primitive; each
memory address In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwa ...
specifies a different byte. The memory address of the initial byte of a datum is considered the memory address (or ''base memory address'') of the entire datum. A ''memory pointer'' (or just ''pointer'') is a primitive, the value of which is intended to be used as a memory address; it is said that ''a pointer points to a memory address''. It is also said that ''a pointer points to a datum n memory' when the pointer's value is the datum's memory address. More generally, a pointer is a kind of
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
, and it is said that ''a pointer references a datum stored somewhere in memory''; to obtain that datum is ''to dereference the pointer''. The feature that separates pointers from other kinds of reference is that a pointer's value is meant to be interpreted as a memory address, which is a rather low-level concept. References serve as a level of indirection: A pointer's value determines which memory address (that is, which datum) is to be used in a calculation. Because indirection is a fundamental aspect of algorithms, pointers are often expressed as a fundamental
data type In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Alg ...
in
programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathematical structure, structure (algebra), space (geometry), and calcu ...

programming language
s; in statically (or strongly) typed programming languages, the
type Type may refer to: Science and technology Computing * Typing, producing text via a keyboard, typewriter, etc. * Data type, collection of values used for computations. * File type * TYPE (DOS command), a command to display contents of a file. * Type ...
of a pointer determines the type of the datum to which the pointer points.


Architectural roots

Pointers are a very thin
abstraction Abstraction in its main sense is a conceptual process where general rules Rule or ruling may refer to: Human activity * The exercise of political Politics (from , ) is the set of activities that are associated with Decision-making, mak ...
on top of the addressing capabilities provided by most modern
architecture upright=1.45, alt=Plan d'exécution du second étage de l'hôtel de Brionne (dessin) De Cotte 2503c – Gallica 2011 (adjusted), Plan of the second floor (attic storey) of the Hôtel de Brionne in Paris – 1734. Architecture (Latin ''archi ...
s. In the simplest scheme, an ''
address An address is a collection of information, presented in a mostly fixed format, used to give the location of a building, apartment, or other structure or a plot of land, generally using political boundaries Borders are geographic Geogr ...
'', or a numeric
index Index may refer to: Arts, entertainment, and media Fictional entities * Index (''A Certain Magical Index''), a character in the light novel series ''A Certain Magical Index'' * The Index, an item on a Halo megastructure in the ''Halo'' series ...
, is assigned to each unit of memory in the system, where the unit is typically either a
byte The byte is a unit of digital information that most commonly consists of eight bit The bit is a basic unit of information in computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It ...
or a
word In linguistics Linguistics is the scientific study of language A language is a structured system of communication used by humans, including speech (spoken language), gestures (Signed language, sign language) and writing. Most lang ...
– depending on whether the architecture is byte-addressable or
word-addressable''Word-addressable'' is a computer architecture term. When the cell size is designed based on the word length of the cpu, then the respective address space is called as word addressable. In computer architecture, a Word (computer architecture), w ...
– effectively transforming all of memory into a very large
array ARRAY, also known as ARRAY Now, is an independent distribution company launched by film maker and former publicist Ava DuVernay Ava Marie DuVernay (; born August 24, 1972) is an American filmmaker. She won the directing award in the U.S. dram ...
. The system would then also provide an operation to retrieve the value stored in the memory unit at a given address (usually utilizing the machine's
general purpose register A processor register is a quickly accessible location available to a computer's processor. Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only. ...
s). In the usual case, a pointer is large enough to hold more addresses than there are units of memory in the system. This introduces the possibility that a program may attempt to access an address which corresponds to no unit of memory, either because not enough memory is installed (i.e. beyond the range of available memory) or the architecture does not support such addresses. The first case may, in certain platforms such as the
Intel x86 x86 is a family of instruction set architecture In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for ...

Intel x86
architecture, be called a
segmentation fault In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
(segfault). The second case is possible in the current implementation of AMD64, where pointers are 64 bit long and addresses only extend to 48 bits. Pointers must conform to certain rules (canonical addresses), so if a non-canonical pointer is dereferenced, the processor raises a
general protection fault A general protection fault (GPF) in the x86 instruction set architecture In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical ...
. On the other hand, some systems have more units of memory than there are addresses. In this case, a more complex scheme such as
memory segmentation Memory segmentation is an operating system memory management (operating systems), memory management technique of division of a computer's primary memory into segments or sections. In a Computer architecture, computer system using segmentation, a r ...
or
paging In computer A computer is a machine that can be programmed to Execution (computing), carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets of operations known as Computer program ...

paging
is employed to use different parts of the memory at different times. The last incarnations of the x86 architecture support up to 36 bits of physical memory addresses, which were mapped to the 32-bit linear address space through the PAE paging mechanism. Thus, only 1/16 of the possible total memory may be accessed at a time. Another example in the same computer family was the 16-bit
protected mode In computing, protected mode, also called protected virtual address mode, is an operational mode of x86 x86 is a family of instruction set architecture In computer science, an instruction set architecture (ISA), also called computer a ...
of the
80286 The Intel Intel Corporation is an American multinational corporation A multinational company (MNC) is a corporate A corporation is an organization—usually a group of people or a company A company, abbreviated as co., is a Le ...

80286
processor, which, though supporting only 16 MB of physical memory, could access up to 1 GB of virtual memory, but the combination of 16-bit address and segment registers made accessing more than 64 KB in one data structure cumbersome. In order to provide a consistent interface, some architectures provide
memory-mapped I/O Memory-mapped I/O (MMIO) and port-mapped I/O (PMIO) are two complementary methods of performing input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a com ...
, which allows some addresses to refer to units of memory while others refer to device registers of other devices in the computer. There are analogous concepts such as file offsets, array indices, and remote object references that serve some of the same purposes as addresses for other types of objects.


Uses

Pointers are directly supported without restrictions in languages such as
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative prog ...
, C,
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, French ...
,
FreeBASIC FreeBASIC is a multiplatform, free/ open source ( GPL) BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages whose design philosop ...
, and implicitly in most
assembly language In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gene ...
s. They are primarily used for constructing
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
s, which in turn are fundamental to constructing nearly all
data structure In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of ...

data structure
s, as well as in passing data between different parts of a program. In functional programming languages that rely heavily on lists, data references are managed abstractly by using primitive constructs like
cons In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, caus ...

cons
and the corresponding elements
car and cdr In computer programming, CAR (car) and CDR (cdr) ( or ) are primitive operations on cons cells (or "non-atomic S-expressions") introduced in the Lisp (programming language), Lisp programming language. A cons cell is composed of two Pointer (comput ...
, which can be thought of as specialised pointers to the first and second components of a cons-cell. This gives rise to some of the idiomatic "flavour" of functional programming. By structuring data in such
cons-lists
cons-lists
, these languages facilitate
recursive Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics Linguistics is the science, scientific study of language. It e ...
means for building and processing data—for example, by recursively accessing the head and tail elements of lists of lists; e.g. "taking the car of the cdr of the cdr". By contrast, memory management based on pointer dereferencing in some approximation of an
array ARRAY, also known as ARRAY Now, is an independent distribution company launched by film maker and former publicist Ava DuVernay Ava Marie DuVernay (; born August 24, 1972) is an American filmmaker. She won the directing award in the U.S. dram ...
of memory addresses facilitates treating variables as slots into which data can be assigned imperatively. When dealing with arrays, the critical
lookup In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of compu ...
operation typically involves a stage called ''address calculation'' which involves constructing a pointer to the desired data element in the array. In other data structures, such as
linked list In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , ...

linked list
s, pointers are used as references to explicitly tie one piece of the structure to another. Pointers are used to pass parameters by reference. This is useful if the programmer wants a function's modifications to a parameter to be visible to the function's caller. This is also useful for returning multiple values from a function. Pointers can also be used to allocate and deallocate dynamic variables and arrays in memory. Since a variable will often become redundant after it has served its purpose, it is a waste of memory to keep it, and therefore it is good practice to deallocate it (using the original pointer reference) when it is no longer needed. Failure to do so may result in a ''
memory leak In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
'' (where available free memory gradually, or in severe cases rapidly, diminishes because of an accumulation of numerous redundant memory blocks).


C pointers

The basic
syntax In linguistics Linguistics is the scientific study of language, meaning that it is a comprehensive, systematic, objective, and precise study of language. Linguistics encompasses the analysis of every aspect of language, as well as the ...
to define a pointer is: int *ptr; This declares ptr as the identifier of an object of the following type: * pointer that points to an object of type int This is usually stated more succinctly as "ptr is a pointer to int." Because the C language does not specify an implicit initialization for objects of automatic storage duration, care should often be taken to ensure that the address to which ptr points is valid; this is why it is sometimes suggested that a pointer be explicitly initialized to the
null pointer In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwar ...
value, which is traditionally specified in C with the standardized macro NULL: ISO/IEC 9899, clause 7.17, paragraph 3: ''NULL... which expands to an implementation-defined null pointer constant...'' int *ptr = NULL; Dereferencing a null pointer in C produces
undefined behavior In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, generati ...
, which could be catastrophic. However, most implementations simply halt execution of the program in question, usually with a
segmentation fault In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
. However, initializing pointers unnecessarily could hinder program analysis, thereby hiding bugs. In any case, once a pointer has been declared, the next logical step is for it to point at something: int a = 5; int *ptr = NULL; ptr = &a; This assigns the value of the address of a to ptr. For example, if a is stored at memory location of 0x8130 then the value of ptr will be 0x8130 after the assignment. To dereference the pointer, an asterisk is used again: *ptr = 8; This means take the contents of ptr (which is 0x8130), "locate" that address in memory and set its value to 8. If a is later accessed again, its new value will be 8. This example may be clearer if memory is examined directly. Assume that a is located at address 0x8130 in memory and ptr at 0x8134; also assume this is a 32-bit machine such that an int is 32-bits wide. The following is what would be in memory after the following code snippet is executed: int a = 5; int *ptr = NULL; : (The NULL pointer shown here is 0x00000000.) By assigning the address of a to ptr: ptr = &a; yields the following memory values: : Then by dereferencing ptr by coding: *ptr = 8; the computer will take the contents of ptr (which is 0x8130), 'locate' that address, and assign 8 to that location yielding the following memory: : Clearly, accessing a will yield the value of 8 because the previous instruction modified the contents of a by way of the pointer ptr.


Use in data structures

When setting up
data structure In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of ...

data structure
s like
lists A ''list'' is any set of items. List or lists may also refer to: People * List (surname)List or Liste is a European surname. Notable people with the surname include: List * Friedrich List (1789–1846), German economist * Garrett List (1943 ...
, queues and trees, it is necessary to have pointers to help manage how the structure is implemented and controlled. Typical examples of pointers are start pointers, end pointers, and stack pointers. These pointers can either be absolute (the actual
physical address In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softw ...
or a
virtual address In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
in
virtual memory In computing, virtual memory, or virtual storage is a Memory management (operating systems), memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "cre ...

virtual memory
) or relative (an
offset Offset or Off-Set may refer to: Arts, entertainment, and media * "Off-Set", a song by T.I. and Young Thug from the ''Furious 7: Original Motion Picture Soundtrack'' * Offset (EP), ''Offset'' (EP), a 2018 EP by singer Kim Chung-ha * Offset (film), ...
from an absolute start address ("base") that typically uses fewer bits than a full address, but will usually require one additional arithmetic operation to resolve). Relative addresses are a form of manual
memory segmentation Memory segmentation is an operating system memory management (operating systems), memory management technique of division of a computer's primary memory into segments or sections. In a Computer architecture, computer system using segmentation, a r ...
, and share many of its advantages and disadvantages. A two-byte offset, containing a 16-bit, unsigned integer, can be used to provide relative addressing for up to 64
KiB The byte is a unit of digital information that most commonly consists of eight bit The bit is a basic unit of information in computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. I ...
(216 bytes) of a data structure. This can easily be extended to 128, 256 or 512 KiB if the address pointed to is forced to be aligned on a half-word, word or double-word boundary (but, requiring an additional "shift left"
bitwise operation In computer programming, a bitwise operation operates on a bit string, a bit array or a Binary numeral system, binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher le ...
—by 1, 2 or 3 bits—in order to adjust the offset by a factor of 2, 4 or 8, before its addition to the base address). Generally, though, such schemes are a lot of trouble, and for convenience to the programmer absolute addresses (and underlying that, a '' flat address space'') is preferred. A one byte offset, such as the hexadecimal
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding Character encoding is the process of assigning numbers to graphical Graphics (from Greek Greek may refer to: Greece Anything of, ...
value of a character (e.g. X'29') can be used to point to an alternative integer value (or index) in an array (e.g., X'01'). In this way, characters can be very efficiently translated from '
raw data Raw data, also known as primary data, are ''data Data (; ) are individual facts, statistics, or items of information, often numeric. In a more technical sense, data are a set of values of qualitative property, qualitative or quantity, qua ...
' to a usable sequential
index Index may refer to: Arts, entertainment, and media Fictional entities * Index (''A Certain Magical Index''), a character in the light novel series ''A Certain Magical Index'' * The Index, an item on a Halo megastructure in the ''Halo'' series ...
and then to an absolute address without a
lookup table In computer science, a lookup table (LUT) is an array data structure, array that replaces runtime (program lifecycle phase), runtime computation with a simpler array indexing operation. The process is termed as "direct addressing" and LUTs differ fr ...
.


C arrays

In C, array indexing is formally defined in terms of pointer arithmetic; that is, the language specification requires that array /code> be equivalent to *(array + i). Thus in C, arrays can be thought of as pointers to consecutive areas of memory (with no gaps), and the syntax for accessing arrays is identical for that which can be used to dereference pointers. For example, an array array can be declared and used in the following manner: int array /* Declares 5 contiguous integers */ int *ptr = array; /* Arrays can be used as pointers */ ptr = 1; /* Pointers can be indexed with array syntax */ *(array + 1) = 2; /* Arrays can be dereferenced with pointer syntax */ *(1 + array) = 2; /* Pointer addition is commutative */ array = 4; /* Subscript operator is commutative */ This allocates a block of five integers and names the block array, which acts as a pointer to the block. Another common use of pointers is to point to dynamically allocated memory from
malloc C dynamic memory allocation refers to performing manual memory management In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical t ...
which returns a consecutive block of memory of no less than the requested size that can be used as an array. While most operators on arrays and pointers are equivalent, the result of the
sizeof sizeof is a unary operator In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathematical structure, structure (algebra), space (geometry), and calculus, change (mathema ...
operator differs. In this example, sizeof(array) will evaluate to 5*sizeof(int) (the size of the array), while sizeof(ptr) will evaluate to sizeof(int*), the size of the pointer itself. Default values of an array can be declared like: int array = ; If array is located in memory starting at address 0x1000 on a 32-bit
little-endian In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softw ...
machine then memory will contain the following (values are in
hexadecimal In mathematics and computing, the hexadecimal (also base 16 or hex) numeral system is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of 16. Unlike the decimal system repres ...
, like the addresses): : Represented here are five integers: 2, 4, 3, 1, and 5. These five integers occupy 32 bits (4 bytes) each with the least-significant byte stored first (this is a little-endian
CPU architecture In computer engineering, computer architecture is a set of rules and methods that describe the functionality, organization, and implementation of computer systems. Some definitions of architecture define it as describing the capabilities and progr ...
) and are stored consecutively starting at address 0x1000. The syntax for C with pointers is: * array means 0x1000; * array + 1 means 0x1004: the "+ 1" means to add the size of 1 int, which is 4 bytes; * *array means to dereference the contents of array. Considering the contents as a memory address (0x1000), look up the value at that location (0x0002); * array /code> means element number i, 0-based, of array which is translated into *(array + i). The last example is how to access the contents of array. Breaking it down: * array + i is the memory location of the (i)th element of array, starting at i=0; * *(array + i) takes that memory address and dereferences it to access the value.


C linked list

Below is an example definition of a
linked list In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , ...

linked list
in C. /* the empty linked list is represented by NULL * or some other sentinel value */ #define EMPTY_LIST NULL struct link ; This pointer-recursive definition is essentially the same as the reference-recursive definition from the
Haskell programming language Haskell is a General-purpose programming language, general-purpose, static typing, statically typed, purely functional programming, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research a ...
: data Link a = Nil , Cons a (Link a) Nil is the empty list, and Cons a (Link a) is a
cons In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, caus ...

cons
cell of type a with another link also of type a. The definition with references, however, is type-checked and does not use potentially confusing signal values. For this reason, data structures in C are usually dealt with via
wrapper function A wrapper function is a subroutine In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming invol ...
s, which are carefully checked for correctness.


Pass-by-address using pointers

Pointers can be used to pass variables by their address, allowing their value to be changed. For example, consider the following C code: /* a copy of the int n can be changed within the function without affecting the calling code */ void passByValue(int n) /* a pointer m is passed instead. No copy of the value pointed to by m is created */ void passByAddress(int *m) int main(void)


Dynamic memory allocation

In some programs, the required memory depends on what ''the user'' may enter. In such cases the programmer needs to allocate memory dynamically. This is done by allocating memory at the ''heap'' rather than on the ''stack'', where variables usually are stored (variables can also be stored in the CPU registers, but that's another matter). Dynamic memory allocation can only be made through pointers, and names (like with common variables) can't be given. Pointers are used to store and manage the addresses of dynamically allocated blocks of memory. Such blocks are used to store data objects or arrays of objects. Most structured and object-oriented languages provide an area of memory, called the ''heap'' or ''free store'', from which objects are dynamically allocated. The example C code below illustrates how structure objects are dynamically allocated and referenced. The standard C library provides the function malloc() for allocating memory blocks from the heap. It takes the size of an object to allocate as a parameter and returns a pointer to a newly allocated block of memory suitable for storing the object, or it returns a null pointer if the allocation failed. /* Parts inventory item */ struct Item ; /* Allocate and initialize a new Item object */ struct Item * make_item(const char *name) The code below illustrates how memory objects are dynamically deallocated, i.e., returned to the heap or free store. The standard C library provides the function free() for deallocating a previously allocated memory block and returning it back to the heap. /* Deallocate an Item object */ void destroy_item(struct Item *item)


Memory-mapped hardware

On some computing architectures, pointers can be used to directly manipulate memory or memory-mapped devices. Assigning addresses to pointers is an invaluable tool when programming
microcontroller A microcontroller (MCU for ''microcontroller unit'') is a small computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern computers can perform generic sets o ...

microcontroller
s. Below is a simple example declaring a pointer of type int and initialising it to a
hexadecimal In mathematics and computing, the hexadecimal (also base 16 or hex) numeral system is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of 16. Unlike the decimal system repres ...
address in this example the constant 0x7FFF: int *hardware_address = (int *)0x7FFF; In the mid 80s, using the
BIOS In computing, BIOS (, ); an acronym for Basic Input/Output System and also known as the System BIOS, ROM BIOS or PC BIOS) is firmware used to perform Computer hardware, hardware initialization during the booting process (power-on startup), and t ...

BIOS
to access the video capabilities of PCs was slow. Applications that were display-intensive typically used to access CGA video memory directly by casting the
hexadecimal In mathematics and computing, the hexadecimal (also base 16 or hex) numeral system is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of 16. Unlike the decimal system repres ...
constant 0xB8000 to a pointer to an array of 80 unsigned 16-bit int values. Each value consisted of an
ASCII ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding Character encoding is the process of assigning numbers to graphical Graphics (from Greek Greek may refer to: Greece Anything of, ...
code in the low byte, and a colour in the high byte. Thus, to put the letter 'A' at row 5, column 2 in bright white on blue, one would write code like the following: #define VID ((unsigned short (*)0xB8000) void foo(void)


Use in control tables

Control table Control tables are table Table may refer to: * Table (information) A table is an arrangement of data Data are units of information Information can be thought of as the resolution of uncertainty; it answers the question of "What an ...

Control table
s that are used to control
program flow In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algor ...
usually make extensive use of pointers. The pointers, usually embedded in a table entry, may, for instance, be used to hold the entry points to
subroutine In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, gener ...
s to be executed, based on certain conditions defined in the same table entry. The pointers can however be simply indexes to other separate, but associated, tables comprising an array of the actual addresses or the addresses themselves (depending upon the programming language constructs available). They can also be used to point to earlier table entries (as in loop processing) or forward to skip some table entries (as in a
switch In electrical engineering Electrical engineering is an engineering discipline concerned with the study, design, and application of equipment, devices, and systems which use electricity, electronics The field of electronics is a branch of p ...
or "early" exit from a loop). For this latter purpose, the "pointer" may simply be the table entry number itself and can be transformed into an actual address by simple arithmetic.


Typed pointers and casting

In many languages, pointers have the additional restriction that the object they point to has a specific
type Type may refer to: Science and technology Computing * Typing, producing text via a keyboard, typewriter, etc. * Data type, collection of values used for computations. * File type * TYPE (DOS command), a command to display contents of a file. * Type ...
. For example, a pointer may be declared to point to an
integer An integer (from the Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally spoken in the area around Rome, known as Latium. Through the power of the Roman Re ...
; the language will then attempt to prevent the programmer from pointing it to objects which are not integers, such as
floating-point number In computing, floating-point arithmetic (FP) is arithmetic using formulaic representation of real numbers as an approximation to support a trade-off between range and precision. For this reason, floating-point computation is often used in system ...
s, eliminating some errors. For example, in C int *money; char *bags; money would be an integer pointer and bags would be a char pointer. The following would yield a compiler warning of "assignment from incompatible pointer type" under GCC bags = money; because money and bags were declared with different types. To suppress the compiler warning, it must be made explicit that you do indeed wish to make the assignment by
typecasting In film, television, and theatre, typecasting is the process by which a particular actor becomes strongly identified with a specific character (arts), character, one or more particular roles, or characters having the same trait theory, traits or co ...
it bags = (char *)money; which says to cast the integer pointer of money to a char pointer and assign to bags. A 2005 draft of the C standard requires that casting a pointer derived from one type to one of another type should maintain the alignment correctness for both types (6.3.2.3 Pointers, par. 7): char *external_buffer = "abcdef"; int *internal_data; internal_data = (int *)external_buffer; // UNDEFINED BEHAVIOUR if "the resulting pointer // is not correctly aligned" In languages that allow pointer arithmetic, arithmetic on pointers takes into account the size of the type. For example, adding an integer number to a pointer produces another pointer that points to an address that is higher by that number times the size of the type. This allows us to easily compute the address of elements of an array of a given type, as was shown in the C arrays example above. When a pointer of one type is cast to another type of a different size, the programmer should expect that pointer arithmetic will be calculated differently. In C, for example, if the money array starts at 0x2000 and sizeof(int) is 4 bytes whereas sizeof(char) is 1 byte, then money + 1 will point to 0x2004, but bags + 1 would point to 0x2001. Other risks of casting include loss of data when "wide" data is written to "narrow" locations (e.g. bags = 65537;), unexpected results when values, and comparison problems, especially with signed vs unsigned values. Although it is impossible in general to determine at compile-time which casts are safe, some languages store
run-time type information In computer programming, run-time type information or run-time type identification (RTTI) is a feature of the C++ programming language that exposes information about an object's data type at Run time (program lifecycle phase), runtime. Run-time typ ...
which can be used to confirm that these dangerous casts are valid at runtime. Other languages merely accept a conservative approximation of safe casts, or none at all.


Value of pointers

In C and C++, the result of comparison between pointers is undefined. In these languages ''and''
LLVM LLVM is a set of compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The ...
, the rule is interpreted to mean that "just because two pointers point to the same address, does not mean they are equal and can be used interchangeably", the difference between the pointers referred to as their ''provenance''. Although casting to an integer type such as uintptr_t offers comparison, the cast itself is implementation-defined. In addition, further conversion to bytes and arithmetic will throw off optimizers trying to keep track the use of pointers, a problem still being elucidated in academic research.


Making pointers safer

As a pointer allows a program to attempt to access an object that may not be defined, pointers can be the origin of a variety of programming errors. However, the usefulness of pointers is so great that it can be difficult to perform programming tasks without them. Consequently, many languages have created constructs designed to provide some of the useful features of pointers without some of their pitfalls, also sometimes referred to as ''pointer hazards''. In this context, pointers that directly address memory (as used in this article) are referred to as s, by contrast with
smart pointer In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce bug ...
s or other variants. One major problem with pointers is that as long as they can be directly manipulated as a number, they can be made to point to unused addresses or to data which is being used for other purposes. Many languages, including most
functional programming language In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Alg ...
s and recent
imperative languages In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algorit ...
like
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
, replace pointers with a more opaque type of reference, typically referred to as simply a ''reference'', which can only be used to refer to objects and not manipulated as numbers, preventing this type of error. Array indexing is handled as a special case. A pointer which does not have any address assigned to it is called a
wild pointer Dangling pointers and wild pointers in computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming invo ...
. Any attempt to use such uninitialized pointers can cause unexpected behavior, either because the initial value is not a valid address, or because using it may damage other parts of the program. The result is often a
segmentation fault In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
,
storage violationIn computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and software. ...
or wild branch (if used as a function pointer or branch address). In systems with explicit memory allocation, it is possible to create a
dangling pointer Dangling pointers and wild pointers in computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred ...
by deallocating the memory region it points into. This type of pointer is dangerous and subtle because a deallocated memory region may contain the same data as it did before it was deallocated but may be then reallocated and overwritten by unrelated code, unknown to the earlier code. Languages with
garbage collection Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of list of waste treatment technologies, treatment or landfill. Waste collection also includes the ...
prevent this type of error because deallocation is performed automatically when there are no more references in scope. Some languages, like
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
, support
smart pointer In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce bug ...
s, which use a simple form of
reference counting In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algo ...
to help track allocation of dynamic memory in addition to acting as a reference. In the absence of reference cycles, where an object refers to itself indirectly through a sequence of smart pointers, these eliminate the possibility of dangling pointers and memory leaks.
Delphi Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracle ...
strings support reference counting natively. The
Rust programming language Rust is a multi-paradigm programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/output, output. Programming languages are used in com ...
introduces a ''borrow checker'', ''pointer lifetimes'', and an optimisation based around optional types for
null pointer In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and softwar ...
s to eliminate pointer bugs, without resorting to
garbage collection Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of list of waste treatment technologies, treatment or landfill. Waste collection also includes the ...
.


Special kinds of pointers


Kinds defined by value


Null pointer

A null pointer has a value reserved for indicating that the pointer does not refer to a valid object. Null pointers are routinely used to represent conditions such as the end of a
list A ''list'' is any set of items. List or lists may also refer to: People * List (surname)List or Liste is a European surname. Notable people with the surname include: List * Friedrich List (1789–1846), German economist * Garrett List (194 ...
of unknown length or the failure to perform some action; this use of null pointers can be compared to
nullable type Nullable types are a feature of some programming languages which allow the value to be set to the special value NULL instead of the usual possible values of the data type. In statically typed languages, a nullable type is an option type, while in d ...
s and to the ''Nothing'' value in an
option type In programming languages (especially functional programming languages) and type theory, an option type or maybe type is a parametric polymorphism, polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return ...
.


Dangling pointer

A dangling pointer is a pointer that does not point to a valid object and consequently may make a program crash or behave oddly. In the
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, French ...
or C programming languages, pointers that are not specifically initialized may point to unpredictable addresses in memory. The following example code shows a dangling pointer: int func(void) Here, p2 may point to anywhere in memory, so performing the assignment *p2 = 'b'; can corrupt an unknown area of memory or trigger a
segmentation fault In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and soft ...
.


Wild branch

Where a pointer is used as the address of the entry point to a program or start of a function which doesn't return anything and is also either uninitialized or corrupted, if a call or jump is nevertheless made to this address, a " wild branch" is said to have occurred. In other words, a wild branch is a function pointer that is wild (dangling). The consequences are usually unpredictable and the error may present itself in several different ways depending upon whether or not the pointer is a "valid" address and whether or not there is (coincidentally) a valid instruction (opcode) at that address. The detection of a wild branch can present one of the most difficult and frustrating debugging exercises since much of the evidence may already have been destroyed beforehand or by execution of one or more inappropriate instructions at the branch location. If available, an
instruction set simulator An instruction set simulator (ISS) is a simulation A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of models; the model represents the key characteristics or behaviors of ...
can usually not only detect a wild branch before it takes effect, but also provide a complete or partial trace of its history.


Kinds defined by structure


Autorelative pointer

An autorelative pointer is a pointer whose value is interpreted as an offset from the address of the pointer itself; thus, if a data structure has an autorelative pointer member that points to some portion of the data structure itself, then the data structure may be relocated in memory without having to update the value of the auto relative pointer. The cited patent also uses the term self-relative pointer to mean the same thing. However, the meaning of that term has been used in other ways: * to mean an offset from the address of a structure rather than from the address of the pointer itself; * to mean a pointer containing its own address, which can be useful for reconstructing in any arbitrary region of memory a collection of data structures that point to each other.


Based pointer

A based pointer is a pointer whose value is an offset from the value of another pointer. This can be used to store and load blocks of data, assigning the address of the beginning of the block to the base pointer.


Kinds defined by use or datatype


Multiple indirection

In some languages, a pointer can reference another pointer, requiring multiple dereference operations to get to the original value. While each level of indirection may add a performance cost, it is sometimes necessary in order to provide correct behavior for complex
data structures 315px, A data structure known as a hash table. In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of dat ...
. For example, in C it is typical to define a
linked list In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , ...

linked list
in terms of an element that contains a pointer to the next element of the list: struct element ; struct element *head = NULL; This implementation uses a pointer to the first element in the list as a surrogate for the entire list. If a new value is added to the beginning of the list, head has to be changed to point to the new element. Since C arguments are always passed by value, using double indirection allows the insertion to be implemented correctly, and has the desirable side-effect of eliminating special case code to deal with insertions at the front of the list: // Given a sorted list at *head, insert the element item at the first // location where all earlier elements have lesser or equal value. void insert(struct element **head, struct element *item) // Caller does this: insert(&head, item); In this case, if the value of item is less than that of head, the caller's head is properly updated to the address of the new item. A basic example is in the
argv In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, gener ...
argument to the main function in C (and C++), which is given in the prototype as char **argv—this is because the variable argv itself is a pointer to an array of strings (an array of arrays), so *argv is a pointer to the 0th string (by convention the name of the program), and **argv is the 0th character of the 0th string.


Function pointer

In some languages, a pointer can reference executable code, i.e., it can point to a function, method, or procedure. A
function pointer A function pointer, also called a subroutine pointer or procedure pointer, is a pointer that points to a function. As opposed to referencing a data value, a function pointer points to executable code within memory. Dereferencing the function poin ...
will store the address of a function to be invoked. While this facility can be used to call functions dynamically, it is often a favorite technique of virus and other malicious software writers. int sum(int n1, int n2) int main(void)


Back pointer

In doubly
linked list In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , ...

linked list
s or tree structures, a back pointer held on an element 'points back' to the item referring to the current element. These are useful for navigation and manipulation, at the expense of greater memory use.


Simulation using an array index

It is possible to simulate pointer behavior using an index to an (normally one-dimensional) array. Primarily for languages which do not support pointers explicitly but ''do'' support arrays, the
array ARRAY, also known as ARRAY Now, is an independent distribution company launched by film maker and former publicist Ava DuVernay Ava Marie DuVernay (; born August 24, 1972) is an American filmmaker. She won the directing award in the U.S. dram ...
can be thought of and processed as if it were the entire memory range (within the scope of the particular array) and any index to it can be thought of as equivalent to a
general purpose register A processor register is a quickly accessible location available to a computer's processor. Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only. ...
in assembly language (that points to the individual bytes but whose actual value is relative to the start of the array, not its absolute address in memory). Assuming the array is, say, a contiguous 16
megabyte The megabyte is a multiple of the unit byte for digital information. Its recommended unit symbol is MB. The unit prefix ''mega'' is a multiplier of (106) in the International System of Units (SI). Therefore, one megabyte is one million bytes o ...
character
data structure In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of ...

data structure
, individual bytes (or a
string String or strings may refer to: *String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * Strings (1991 film), ''Strings'' (1991 fil ...
of contiguous bytes within the array) can be directly addressed and manipulated using the name of the array with a 31 bit unsigned
integer An integer (from the Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally spoken in the area around Rome, known as Latium. Through the power of the Roman Re ...
as the simulated pointer (this is quite similar to the ''C arrays'' example shown above). Pointer arithmetic can be simulated by adding or subtracting from the index, with minimal additional overhead compared to genuine pointer arithmetic. It is even theoretically possible, using the above technique, together with a suitable
instruction set simulator An instruction set simulator (ISS) is a simulation A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of models; the model represents the key characteristics or behaviors of ...
to simulate ''any''
machine code In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, c ...
or the intermediate (
byte code Bytecode, also termed portable code or p-code, is a form of instruction set In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions ...
) of ''any'' processor/language in another language that does not support pointers at all (for example
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
/
JavaScript JavaScript (), often abbreviated JS, is a programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), ma ...

JavaScript
). To achieve this, the
binary Binary may refer to: Science and technology Mathematics * Binary number In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system, which uses only two symbols: ty ...
code can initially be loaded into contiguous bytes of the array for the simulator to "read", interpret and action entirely within the memory contained of the same array. If necessary, to completely avoid
buffer overflow In information security #REDIRECT Information security Information security, sometimes shortened to infosec, is the practice of protecting information by mitigating information risks. It is part of Risk management information systems, information ...
problems,
bounds checking In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, generati ...
can usually be actioned for the compiler (or if not, hand coded in the simulator).


Support in various programming languages


Ada

Ada Ada may refer to: Places Africa * Ada Foah Ada Foah is a town on the southeast coast of Ghana, where the Volta River meets the Atlantic Ocean. The town is located along the Volta River, off of the Accra-Aflao motorway. Known for Palm tree, pal ...
is a strongly typed language where all pointers are typed and only safe type conversions are permitted. All pointers are by default initialized to null, and any attempt to access data through a null pointer causes an exception to be raised. Pointers in Ada are called '' access types''. Ada 83 did not permit arithmetic on access types (although many compiler vendors provided for it as a non-standard feature), but Ada 95 supports “safe” arithmetic on access types via the package System.Storage_Elements.


BASIC

Several old versions of
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming language In computer science Computer science deals with the theoretical foundations of information, algorithms and the ar ...

BASIC
for the Windows platform had support for STRPTR() to return the address of a string, and for VARPTR() to return the address of a variable. Visual Basic 5 also had support for OBJPTR() to return the address of an object interface, and for an ADDRESSOF operator to return the address of a function. The types of all of these are integers, but their values are equivalent to those held by pointer types. Newer dialects of
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming language In computer science Computer science deals with the theoretical foundations of information, algorithms and the ar ...

BASIC
, such as
FreeBASIC FreeBASIC is a multiplatform, free/ open source ( GPL) BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages whose design philosop ...
or
BlitzMax Blitz BASIC is the programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters ar ...
, have exhaustive pointer implementations, however. In FreeBASIC, arithmetic on ANY pointers (equivalent to C's void*) are treated as though the ANY pointer was a byte width. ANY pointers cannot be dereferenced, as in C. Also, casting between ANY and any other type's pointers will not generate any warnings. dim as integer f = 257 dim as any ptr g = @f dim as integer ptr i = g assert(*i = 257) assert( (g + 4) = (@f + 1) )


C and C++

In C and
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
pointers are variables that store addresses and can be ''null''. Each pointer has a type it points to, but one can freely cast between pointer types (but not between a function pointer and an object pointer). A special pointer type called the “void pointer” allows pointing to any (non-function) object, but is limited by the fact that it cannot be dereferenced directly (it shall be cast). The address itself can often be directly manipulated by casting a pointer to and from an integral type of sufficient size, though the results are implementation-defined and may indeed cause undefined behavior; while earlier C standards did not have an integral type that was guaranteed to be large enough,
C99 C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language C (, as in the letter ''c'') is a general-purpose, procedural computer programming language A programming language ...

C99
specifies the uintptr_t ''
typedef typedef is a reserved keyword in the programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (fo ...
name'' defined in , but an implementation need not provide it.
C++ C++ () is a general-purpose programming language In computer software, a general-purpose programming language is a programming language dedicated to a general-purpose, designed to be used for writing software in a wide variety of application ...

C++
fully supports C pointers and C typecasting. It also supports a new group of typecasting operators to help catch some unintended dangerous casts at compile-time. Since
C++11 C11, C.XI, C-11 or C.11 may refer to: Transport * C-11 Fleetster The Consolidated Model 17 Fleetster was a 1920s United States, American light transport monoplane aircraft built by the Consolidated Aircraft, Consolidated Aircraft Corporation. De ...
, the
C++ standard library The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard. ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it ...
also provides
smart pointer In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce bug ...
s (unique_ptr, shared_ptr and weak_ptr) which can be used in some situations as a safer alternative to primitive C pointers. C++ also supports another form of reference, quite different from a pointer, called simply a ''
reference Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
'' or ''reference type''. Pointer arithmetic, that is, the ability to modify a pointer's target address with arithmetic operations (as well as magnitude comparisons), is restricted by the language standard to remain within the bounds of a single array object (or just after it), and will otherwise invoke
undefined behavior In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, generati ...
. Adding or subtracting from a pointer moves it by a multiple of the size of its
datatype In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of c ...
. For example, adding 1 to a pointer to 4-byte integer values will increment the pointer's pointed-to byte-address by 4. This has the effect of incrementing the pointer to point at the next element in a contiguous array of integers—which is often the intended result. Pointer arithmetic cannot be performed on void pointers because the
void type The void type, in several Curly bracket programming language, programming languages derived from C and Algol68, is the type theory, type for the result of a function (computer science), function that returns normally, but does not provide a result ...
has no size, and thus the pointed address can not be added to, although gcc and other compilers will perform byte arithmetic on void* as a non-standard extension, treating it as if it were char *. Pointer arithmetic provides the programmer with a single way of dealing with different types: adding and subtracting the number of elements required instead of the actual offset in bytes. (Pointer arithmetic with char * pointers uses byte offsets, because sizeof(char) is 1 by definition.) In particular, the C definition explicitly declares that the syntax a /code>, which is the n-th element of the array a, is equivalent to *(a + n), which is the content of the element pointed by a + n. This implies that n /code> is equivalent to a /code>, and one can write, e.g., a /code> or 3 /code> equally well to access the fourth element of an array a. While powerful, pointer arithmetic can be a source of computer bugs. It tends to confuse novice
programmer A computer programmer, sometimes called a software developer, a programmer or more recently a coder (especially in more informal contexts), is a person who creates computer software Software is a collection of Instruction (computer science ...

programmer
s, forcing them into different contexts: an expression can be an ordinary arithmetic one or a pointer arithmetic one, and sometimes it is easy to mistake one for the other. In response to this, many modern high-level computer languages (for example
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
) do not permit direct access to memory using addresses. Also, the safe C dialect
Cyclone In meteorology Meteorology is a branch of the (which include and ), with a major focus on . The study of meteorology dates back , though significant progress in meteorology did not begin until the 18th century. The 19th century saw mo ...
addresses many of the issues with pointers. See
C programming language C (, as in the letter ''c'') is a general-purpose, procedural computer programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/outp ...

C programming language
for more discussion. The void pointer, or void*, is supported in ANSI C and C++ as a generic pointer type. A pointer to void can store the address of any object (not function), and, in C, is implicitly converted to any other object pointer type on assignment, but it must be explicitly cast if dereferenced. C used char* for the “type-agnostic pointer” purpose (before ANSI C). int x = 4; void* p1 = &x; int* p2 = p1; // void* implicitly converted to int*: valid C, but not C++ int a = *p2; int b = *(int*)p1; // when dereferencing inline, there is no implicit conversion C++ does not allow the implicit conversion of void* to other pointer types, even in assignments. This was a design decision to avoid careless and even unintended casts, though most compilers only output warnings, not errors, when encountering other casts. int x = 4; void* p1 = &x; int* p2 = p1; // this fails in C++: there is no implicit conversion from void* int* p3 = (int*)p1; // C-style cast int* p4 = static_cast(p1); // C++ cast In C++, there is no void& (reference to void) to complement void* (pointer to void), because references behave like aliases to the variables they point to, and there can never be a variable whose type is void.


Pointer declaration syntax overview

These pointer declarations cover most variants of pointer declarations. Of course it is possible to have triple pointers, but the main principles behind a triple pointer already exist in a double pointer. char cff /* array of arrays of chars */ char *cfp /* array of pointers to chars */ char **cpp; /* pointer to pointer to char ("double pointer") */ char (*cpf) /* pointer to array(s) of chars */ char *cpF(); /* function which returns a pointer to char(s) */ char (*CFp)(); /* pointer to a function which returns a char */ char (*cfpF()) /* function which returns pointer to an array of chars */ char (*cpFf (); /* an array of pointers to functions which return a char */ The () and [] have a higher priority than *.


C#

In the C Sharp (programming language), C# programming language, pointers are supported only under certain conditions: any block of code including pointers must be marked with the unsafe keyword. Such blocks usually require higher security permissions to be allowed to run. The syntax is essentially the same as in C++, and the address pointed can be either managed or unmanaged memory. However, pointers to managed memory (any pointer to a managed object) must be declared using the fixed keyword, which prevents the garbage collector from moving the pointed object as part of memory management while the pointer is in scope, thus keeping the pointer address valid. An exception to this is from using the IntPtr structure, which is a safe managed equivalent to int*, and does not require unsafe code. This type is often returned when using methods from the System.Runtime.InteropServices, for example: // Get 16 bytes of memory from the process's unmanaged memory IntPtr pointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(16); // Do something with the allocated memory // Free the allocated memory System.Runtime.InteropServices.Marshal.FreeHGlobal(pointer); The
.NET framework The .NET Framework (pronounced as "''dot net"'') is a software framework In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or t ...
includes many classes and methods in the System and System.Runtime.InteropServices namespaces (such as the Marshal class) which convert .NET types (for example, System.String) to and from many unmanaged types and pointers (for example, LPWSTR or void*) to allow communication with unmanaged code. Most such methods have the same security permission requirements as unmanaged code, since they can affect arbitrary places in memory.


COBOL

The
COBOL COBOL (; an acronym An acronym is a word In linguistics, a word of a spoken language can be defined as the smallest sequence of phonemes that can be uttered in isolation with semantic, objective or pragmatics, practical meaning (lingui ...

COBOL
programming language supports pointers to variables. Primitive or group (record) data objects declared within the LINKAGE SECTION of a program are inherently pointer-based, where the only memory allocated within the program is space for the address of the data item (typically a single memory word). In program source code, these data items are used just like any other WORKING-STORAGE variable, but their contents are implicitly accessed indirectly through their LINKAGE pointers. Memory space for each pointed-to data object is typically allocated dynamically using external CALL statements or via embedded extended language constructs such as EXEC CICS or statements. Extended versions of COBOL also provide pointer variables declared with USAGE IS POINTER clauses. The values of such pointer variables are established and modified using SET and SET ADDRESS statements. Some extended versions of COBOL also provide PROCEDURE-POINTER variables, which are capable of storing the addresses of executable code.


PL/I

The
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative prog ...
language provides full support for pointers to all data types (including pointers to structures),
recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics Linguistics is the scientific study of language, meaning tha ...

recursion
, multitasking, string handling, and extensive built-in
function Function or functionality may refer to: Computing * Function key A function key is a key on a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern comp ...
s. PL/I was quite a leap forward compared to the programming languages of its time. PL/I pointers are untyped, and therefore no casting is required for pointer dereferencing or assignment. The declaration syntax for a pointer is DECLARE xxx POINTER;, which declares a pointer named "xxx". Pointers are used with BASED variables. A based variable can be declared with a default locator (DECLARE xxx BASED(ppp); or without (DECLARE xxx BASED;), where xxx is a based variable, which may be an element variable, a structure, or an array, and ppp is the default pointer). Such a variable can be address without an explicit pointer reference (xxx=1;, or may be addressed with an explicit reference to the default locator (ppp), or to any other pointer (qqq->xxx=1;). Pointer arithmetic is not part of the PL/I standard, but many compilers allow expressions of the form ptr = ptr±expression. IBM PL/I also has the builtin function PTRADD to perform the arithmetic. Pointer arithmetic is always performed in bytes. IBM ''Enterprise'' PL/I compilers have a new form of typed pointer called a HANDLE.


D

The
D programming language D, also known as Dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engine ...
is a derivative of C and C++ which fully supports C pointers and C typecasting.


Eiffel

The Eiffel object-oriented language employs value and reference semantics without pointer arithmetic. Nevertheless, pointer classes are provided. They offer pointer arithmetic, typecasting, explicit memory management, interfacing with non-Eiffel software, and other features.


Fortran

introduced a strongly typed pointer capability. Fortran pointers contain more than just a simple memory address. They also encapsulate the lower and upper bounds of array dimensions, strides (for example, to support arbitrary array sections), and other metadata. An ''association operator'', => is used to associate a POINTER to a variable which has a TARGET attribute. The Fortran-90 ALLOCATE statement may also be used to associate a pointer to a block of memory. For example, the following code might be used to define and create a linked list structure: type real_list_t real :: sample_data(100) type (real_list_t), pointer :: next => null () end type type (real_list_t), target :: my_real_list type (real_list_t), pointer :: real_list_temp real_list_temp => my_real_list do read (1,iostat=ioerr) real_list_temp%sample_data if (ioerr /= 0) exit allocate (real_list_temp%next) real_list_temp => real_list_temp%next end do Fortran-2003 adds support for procedure pointers. Also, as part of the ''C Interoperability'' feature, Fortran-2003 supports intrinsic functions for converting C-style pointers into Fortran pointers and back.


Go

Go has pointers. Its declaration syntax is equivalent to that of C, but written the other way around, ending with the type. Unlike C, Go has garbage collection, and disallows pointer arithmetic. Reference types, like in C++, do not exist. Some built-in types, like maps and channels, are boxed (i.e. internally they are pointers to mutable structures), and are initialized using the make function. In an approach to unified syntax between pointers and non-pointers, the arrow (->) operator has been dropped: the dot operator on a pointer refers to the field or method of the dereferenced object. This, however, only works with 1 level of indirection.


Java

There is no explicit representation of pointers in
Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 147.7 million people, Java is the world's List of ...
. Instead, more complex data structures like objects and
arrays ARRAY, also known as ARRAY Now, is an independent distribution company launched by film maker and former publicist Ava DuVernay Ava Marie DuVernay (; born August 24, 1972) is an American filmmaker. She won the directing award in the U.S. dram ...
are implemented using
references Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
. The language does not provide any explicit pointer manipulation operators. It is still possible for code to attempt to dereference a null reference (null pointer), however, which results in a run-time exception being thrown. The space occupied by unreferenced memory objects is recovered automatically by
garbage collection Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of list of waste treatment technologies, treatment or landfill. Waste collection also includes the ...
at run-time.


Modula-2

Pointers are implemented very much as in Pascal, as are VAR parameters in procedure calls.
Modula-2 Modula-2 is a structured, procedural programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol ( ...
is even more strongly typed than Pascal, with fewer ways to escape the type system. Some of the variants of Modula-2 (such as
Modula-3 Modula-3 is a programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are take ...

Modula-3
) include garbage collection.


Oberon

Much as with Modula-2, pointers are available. There are still fewer ways to evade the type system and so
Oberon Oberon () is a king of the fairies A fairy (also ''fay'', ''fae'', ''fey'', ''fair folk'', or ''faerie'') is a type of mythical Myth is a folklore genre Folklore is the expressive body of culture shared by a particular group of pe ...
and its variants are still safer with respect to pointers than Modula-2 or its variants. As with
Modula-3 Modula-3 is a programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters are take ...

Modula-3
, garbage collection is a part of the language specification.


Pascal

Unlike many languages that feature pointers, standard
ISO The International Organization for Standardization (ISO ) is an international standard An international standard is a technical standard A technical standard is an established norm Norm, the Norm or NORM may refer to: In academic discipline ...
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, French ...
only allows pointers to reference dynamically created variables that are anonymous and does not allow them to reference standard static or local variables. It does not have pointer arithmetic. Pointers also must have an associated type and a pointer to one type is not compatible with a pointer to another type (e.g. a pointer to a char is not compatible with a pointer to an integer). This helps eliminate the type security issues inherent with other pointer implementations, particularly those used for
PL/I PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative prog ...
or C. It also removes some risks caused by dangling pointers, but the ability to dynamically let go of referenced space by using the dispose standard procedure (which has the same effect as the free library function found in C) means that the risk of dangling pointers has not been entirely eliminated. However, in some commercial and open source Pascal (or derivatives) compiler implementations —like
Free Pascal Free Pascal Compiler (FPC) is a compiler for the closely related programming-language dialects Pascal (programming language), Pascal and Object Pascal. It is free software released under the GNU General Public License, witexception clausesthat al ...
,
Turbo Pascal Turbo Pascal is a software development system that includes a compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into ano ...
or the
Object Pascal Object Pascal is an extension to the programming language Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of ...
in
Embarcadero Delphi Delphi is a software product that uses the Delphi dialect of the Object Pascal Object Pascal is an extension to the programming language Pascal that provides object-oriented programming Object-oriented programming (OOP) is a programming pa ...
— a pointer is allowed to reference standard static or local variables and can be cast from one pointer type to another. Moreover, pointer arithmetic is unrestricted: adding or subtracting from a pointer moves it by that number of bytes in either direction, but using the Inc or Dec standard procedures with it moves the pointer by the size of the
data type In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Alg ...
it is ''declared'' to point to. An untyped pointer is also provided under the name Pointer, which is compatible with other pointer types.


Perl

The
Perl Perl is a family of two high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific Objective (goal), goals of a systematic operation; and are applied in a wide range of contexts, such as, for ...
programming language A programming language is a formal language In mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathematical structure, structure (algebra), space (geometry), and calcu ...

programming language
supports pointers, although rarely used, in the form of the pack and unpack functions. These are intended only for simple interactions with compiled OS libraries. In all other cases, Perl uses
references Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name ...
, which are typed and do not allow any form of pointer arithmetic. They are used to construct complex data structures.


See also

* Address constant *
Bounded pointer In computer science, a bounded pointer is a pointer (computer programming), pointer that is augmented with additional information that enable the storage bounds within which it may point to be deduced. This additional information sometimes takes the ...
*
Buffer overflow In information security #REDIRECT Information security Information security, sometimes shortened to infosec, is the practice of protecting information by mitigating information risks. It is part of Risk management information systems, information ...
* Fat pointer *
Function pointer A function pointer, also called a subroutine pointer or procedure pointer, is a pointer that points to a function. As opposed to referencing a data value, a function pointer points to executable code within memory. Dereferencing the function poin ...
* Hazard pointer *
Opaque pointer In computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task. Programming involves tasks such as analysis, generat ...
*
Pointer swizzling In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , ...
*
Reference (computer science) In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of comp ...
*
Static program analysis Static program analysis is the analysis of computer software that is performed without actually executing programs, in contrast with dynamic analysis, which is analysis performed on programs while they are executing. In most cases the analysis is ...
*
Storage violationIn computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and software. ...
*
Tagged pointerIn computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algorith ...
*
Variable (computer science) In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, cause ...
*
Zero-based numbering Zero-based numbering is a way of numbering in which the initial element of a sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order theory, order matters. Like a Set (mathematics), s ...
*
Iterator In computer programming, an iterator is an object (computing), object that enables a programmer to traverse a Container (data structure), container, particularly List (abstract data type), lists. Various types of iterators are often provided via a ...


References


External links


PL/I List Processing
Paper from the June, 1967 issue of CACM
cdecl.org
A tool to convert pointer declarations to plain English
Over IQ.com
A beginner level guide describing pointers in a plain English.
Pointers and Memory
Introduction to pointers – Stanford Computer Science Education Library

A visual model for the beginners in C programming
0pointer.de
A terse list of minimum length source codes that dereference a null pointer in several different programming languages

*. {{DEFAULTSORT:Pointer (Computing) Articles with example C code Data types Primitive types American inventions sv:Datatyp#Pekare och referenstyper