Information AboutPointer |
|
In Computer Science , a pointer is a Programming Language Datatype whose value refers directly to ("points to") another value stored elsewhere in the Computer Memory using its Address . Obtaining the value that a pointer refers to is called '''dereferencing''' the pointer. A pointer is a simple implementation of the general Reference datatype (although it is quite different from the facility referred to as a '' Reference '' in C++). Pointers are so commonly used as references that sometimes people use the word "pointer" to refer to references in general; however, more properly it only applies to data structures whose interface explicitly allows it to be manipulated as a memory address. If you are seeking general information on a small piece of data used to find an object, see Reference (computer Science) . ARCHITECTURAL ROOTS Pointers are a very thin abstraction on top of the addressing capabilities provided by most modern architectures. In the simplest scheme, an '' Address '', or a numeric Index , is assigned to each unit of memory in the system, where the unit is typically either a Byte or a Word , effectively transforming all of memory into a very large Array . Then, if we have an address, the system provides an operation to retrieve the value stored in the memory unit at that address. Pointers are Datatype s which hold addresses. See Reference (computer Science) . In the usual case, a pointer is large enough to hold more different 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, called a Segmentation Fault . 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 or Paging is employed to use different parts of the memory at different times. In order to provide a consistent interface, some architectures provide Memory-mapped I/O , which allows some addresses to refer to units of memory while others refer to Device Register s 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 C , C++ , Pascal and most Assembly Language s. They are primarily used for constructing Reference s, which in turn are fundamental to constructing nearly all Data Structure s, as well as in passing data between different parts of a program. When dealing with Array s, the critical lookup 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 lists, 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 we want 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. Examples of use Below is an example of the definition of a Linked List in C; this is not possible in C without pointers.
#define EMPTY_LIST NULL struct link {
}; Note that this pointer-recursive definition is essentially the same as the reference-recursive definition from the Haskell Programming Language : data Link a = Nil {- the empty list -} |