Pointer_arithmetic Pointer_arithmetic

Pointer arithmetic - Definition and Overview

Related Words: Analysis, Calculation, Calculus, Estimation, Geodesy, Geometry
This article or section should be merged with pointer.

Pointer arithmetic is a particular arithmetic involving pointers, typical of the C programming language.

In pointer arithmetic, the unit is the size of the pointer's type. For example, adding 1 to a pointer to integer values (which typically span 4 bytes) will increment the pointer by 4. But, the end result will be in the pointer pointing right at the next element, which was probably the intended result.

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 particular, the C definition explicitly declares that the syntax a[n], which is the n-th element of the array pointed by a, is equivalent to *(a+n), which is the content of the element pointed by a+n.

While powerful, pointer arithmetic is an endless source of computer bugs. It tends to confuse programmers, 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.

Many modern high level computer languages (for example Java) do not permit direct access to memory using addresses, so concepts of pointers and pointer arithmetic are not relevant. This is often deliberate, as many programming tasks do not require specific knowledge of where and how in computer memory data is stored.

Example Usage of arithmetic

Dawnwyr: In the arithmetic of love, one plus one equals everything, and two minus one equals nothing. ~Mignon McLaughlin
IamJor_el: In the arithmetic of love, one plus one equals everything, and two minus one equals nothing.
FACLC: @chrispowell @markpoppen The Wheat-Herders have trouble with basic arithmetic?
Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.