Tous les livres

Professionnel

Applis À propos Coach Connexion Commencer la lecture

Computer Science · Glossaire

Qu'est-ce que « Pointer arithmetic » ?

Definition 4.4 University Computer Science — Year 1 · Chapitre 4 — Pointers and Arrays

If p points to element ii of an array, p + k points to element i+ki + k: pointer arithmetic counts in elements, not bytes, so the address grows by kk times the size of an element. The result must point into the array or exactly one element past its end. The difference q - p of two pointers into the same array is the number of elements between them, of type ptrdiff_t. By definition a[i] means *(a + i).

An array of five int. The pointer a + k designates element k, 4k bytes from the start; a[k] and *(a + k) are the same element. The position after the last element can be pointed to but holds nothing of the array.
An array of five int. The pointer a + k designates element kk, 4k4k bytes from the start; a[k] and *(a + k) are the same element. The position after the last element can be pointed to but holds nothing of the array.
Lire dans le chapitre →