Pointer (computer programming)

[citation needed] Because pointers allow both protected and unprotected access to memory addresses, there are risks associated with using them, particularly in the latter case.

[2] In 2000, Lawson was presented the Computer Pioneer Award by the IEEE "[f]or 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".

A pointer is a programming concept used in computer science to reference or point to a memory location that stores a value or an object.

In simpler terms, you can think of a pointer as an arrow that points to a specific spot in a computer's memory, allowing you to interact with the data stored at that location.

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.

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 registers).

In functional programming languages that rely heavily on lists, data references are managed abstractly by using primitive constructs like cons and the corresponding elements car and cdr, which can be thought of as specialised pointers to the first and second components of a cons-cell.

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.

To dereference the pointer, an asterisk is used again: This means take the contents of ptr (which is 0x8130), "locate" that address in memory and set its value to 8.

A two-byte offset, containing a 16-bit, unsigned integer, can be used to provide relative addressing for up to 64 KiB (216 bytes) of a data structure.

In this way, characters can be very efficiently translated from 'raw data' to a usable sequential index and then to an absolute address without a lookup table.

Most structured and object-oriented languages provide an area of memory, called the heap or free store, from which objects are dynamically allocated.

The standard C library provides the function free() for deallocating a previously allocated memory block and returning it back to the heap.

Applications that were display-intensive typically used to access CGA video memory directly by casting the hexadecimal constant 0xB8000 to a pointer to an array of 80 unsigned 16-bit int values.

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.

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.

Languages with garbage collection prevent this type of error because deallocation is performed automatically when there are no more references in scope.

If available, an instruction set simulator can usually not only detect a wild branch before it takes effect, but also provide a complete or partial trace of its history.

While each level of indirection may add a performance cost, it is sometimes necessary in order to provide correct behavior for complex data structures.

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: 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.

If necessary, to completely avoid buffer overflow problems, bounds checking can usually be inserted by the compiler (or if not, hand coded in the simulator).

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 specifies the uintptr_t typedef name defined in , but an implementation need not provide it.

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.

In response to this, many modern high-level computer languages (for example Java) do not permit direct access to memory using addresses.

However, an exception to this is from using the IntPtr structure, which is a memory managed equivalent to int*, and does not require the unsafe keyword nor the CompilerServices assembly.

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.

Some extended versions of COBOL also provide PROCEDURE-POINTER variables, which are capable of storing the addresses of executable code.

For example, the following code might be used to define and create a linked list structure: Fortran-2003 adds support for procedure pointers.

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.

The Perl programming language supports pointers, although rarely used, in the form of the pack and unpack functions.

A pointer a pointing to the memory address associated with a variable b, i.e., a contains the memory address 1008 of the variable b . In this diagram, the computing architecture uses the same address space and data primitive for both pointers and non-pointers; this need not be the case.