Todos os livros

Profissional

Apps Sobre Coach Entrar Começar a ler

Computer Science · Glossário

O que é Pointer arithmetic?

Definition 4.4 University Computer Science — Year 1 · Capítulo 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.
Ler no capítulo →