Clip Art

Pointer

In programming languages, a pointer is a datatype whose value is used to refer to another value stored elsewhere in the computer memory. The operation of finding the object that a pointer refers to is called dereferencing the pointer.

In its implementation, pointers are mere integer representing the memory address of referring values, typically with the same size as that of int type. Arrays are passed as a pointer to functions.

Operations with pointers are more efficient in runtime performance than similar operations using array indices, but are potentially unsafe. In many languages that provide pointers, pointers can be set to point to an arbitrary memory address, including addresses that do not correspond to part of the program's address space or that contain data that should not be altered. In the C programming language and it descendants, pointers are often used to hold the base address of arrays. Languages like C that provide for direct manipulation of pointer values can create problems with address alignment: it is possible to move a pointer by one byte even though the thing it is pointing to is actually 4 bytes long. Though such languages provide mechanisms that discourage such problems (for example, in C, adding 1 to a pointer to a 4-byte object increases the address stored in the pointer by 4 bytes), the confusion that sometimes results from a mismatch between the programmer's and compiler's interpretation of the pointer can be a source of subtle programming bugs. Many languages, including most functional programming languages and recent imperative languages like Java, replace pointers with references, which are more constrained in how they can be manipulated and prevented many classes of programming errors.

One of the disadvantages of the pointer is that it is limited to accessing a fixed amount of memory, dictated by the size of the pointer. Since modern applications demand the simultaneous access to hundreds of megabytes of information, pointers of 32 bits are widely used, but this limits addressable memory to 232 bytes. Pointers generally can only point to memory, not directly to data in disk space and other computers connected via a network. Use of opaque data structure such as smart pointers or handles is a common solution for this kind of problem.

Pointers in C

The null pointer is one of the controversial features of the C programming language. The null pointer is defined as appearing to point to memory location 0, though its internal implementation may in fact point elsewhere. Null pointers are used routinely by C programmers to represent exceptional conditions such as the lack of a successor to the last element of a linked list; this usage is similar to the use of null values in relational databases. However, dereferencing a null pointer causes a run-time error that usually terminates the programming immediately (the best case), or in some implementations quietly writes data to memory location zero, which may be being used for some important aspect of the machine's operation.

C++, a derivant of C provides autoptr, a sort of smart pointer which can be used as safe alternative to the primitive pointers of C.


The pointer in computing can also be another name for the computer mouse cursor.


Pointer also refers to a group of dog breeds. Examples of pointers include: German Shorthair Pointer, Hungarian Vizsla, Weimaraner and others.