You can access the elements of an array is a second way aswell.
[source lang="cpp"]int array[10]; // create the arrayint *p = array; // create a pointer of the same type and assign it to the start of the array.[/source]
Now, using pointer arithmetics, you can access the elements by adding a number to the pointer, such as "p+1", which is the same thing as array[1]. "p" by itself would be the same thing as array[0]. This actually what arrays do, but I think the compiler keeps a note on how many elements the array was created with, to help you with not going out of bounds.
Also, you need to "delete" arrays that have been created with "new" by typing "delete[]".
Pointer ariothmetics is not just an alternative way of traversing an array, but is something more or less needed, so it's good to know it.
I'm a bit rusty on programming atm, so don't bash me too hard if I wrote something stupid or made some silly mistake.
EDIT: oh, and using an array normally (array[0]) dereferences automatically, but if you use "p", it's not dereferenced, so you need to write "*p" to get the actual value of the element, instead of the address to it. Just wanted to point that out, even if I felt it was obvious.
Edited by antiHUMANDesigns, 26 June 2012 - 10:37 AM.