Zwischen Zeigern und Feldern besteht in C/C++ ein enger Zusammenhang
(Zeiger-Feld-Dualität), der sich bereits oben in der Verwendung von
[] zur ``indirekten'' Dereferenzierung von Pointern andeutete.
Ein Feld a[..] wird intern durch den Compiler sofort in einen Pointer
auf dessen erstes Element verwandelt. Der Feldzugriff wird dann
vollständig nach den Regeln der Pointerarithmetik abgewickelt. Dies
ist auch der tiefere Grund dafür, daß C/C++-Felder immer bei 0
beginnen (man spart dabei Rechenoperationen bei der Lokalisierung von
Adressen).
int a[20];
int *p = a; // ok, a is name of the field and can
// be used as address to the field
int *p = &(a[0]); // ... equivalent
p[5] = 4; // access to a through pointer arithmetic,
// a[5] is set to the value of 4
a[5] = 4; // ... equivalent
int b[20][30]; // b is now an array of 20 arrays of
// 30 elements of type int
// int *p = b; error! wrong type, since
// b is of type pointer to 30 int here
int *r = b[0]; // ok, r points to the first int
// in the first (of 20) array(s) of 30 ints
int (*q)[30] = b; // ok, q points to the first set of 30 int's,
// q and b can now be used synonymous
q[12][15] = 26; // ok, set element (13,16) to the value 26
(*(q+12))[15] = 26; // ... equivalent
*(*(q+12)+15) = 26; // ... equivalent
b[12][15] = 26; // ... equivalent