Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
* En cliquant sur ce bouton, vous acceptez notre politique de confidentialité

Free PVS-Studio license for Microsoft MVP specialists
To get the licence for your open-source project, please fill out this form
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

I am interested to try it on the platforms:
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

Votre message a été envoyé.

Nous vous répondrons à

Si vous n'avez toujours pas reçu de réponse, vérifiez votre dossier
Spam/Junk et cliquez sur le bouton "Not Spam".
De cette façon, vous ne manquerez la réponse de notre équipe.

Address arithmetic

Address arithmetic

31 Mar 2013

Address arithmetic is a method of calculating the address of an object with the help of arithmetic operations on pointers and use of pointers in comparison operations. Address arithmetic is also called pointer arithmetic.

According to C and C++ language standards, the result address must remain strictly within the bounds of a single array object (or just after it). Adding or subtracting from a pointer moves it by a multiple of the size of the data type it points to. For example, assume we have a pointer to an array of 4-byte integers. Incrementing this pointer will increment its value by 4 (the size of the element). This effect is often used to increment a pointer to point at the next element in a contiguous array of integers.

Pointer arithmetic cannot be performed on void pointers because the void type has no size, and thus the pointed address cannot be added to. However, there are non-standard compiler extensions allowing byte arithmetic on void* pointers.

Pointers and integer variables are not interchangeable. Null constant is the only exception from this rule: it can be assigned to the pointer, and the pointer can be compared to null constant. As a rule, to show that null is a special value for the pointer, NULL constant is written instead of number "0".

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[i], which is the i-th element of the array A, is equivalent to *(A+i), which is the content of the element pointed by A+i. This also implies that i[A] is equivalent to A[i].

At the same time, powerful pointer arithmetic can be a source of errors. Address arithmetic is a restrictive stage in the process of mastering 64-bit systems for the old C/C++ program code can contain a lot of errors relating to the use of pointers. To learn more about this problem see the article "20 issues of porting C++ code on the 64-bit platform".

Because of the challenges of using pointers, many modern high level computer languages (for example, Java or C#) do not permit direct access to memory using addresses.


Comments (0)

Next comments
Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus