Saturday, May 22, 2010

C++ how do I point to an element in an existing array?

How can I create a pointer that points to a specific item in an existing array (say item 5) and will let me then use that pointer like an array?





Here is my code:


http://www.marcovitanza.com/pointerArray...

C++ how do I point to an element in an existing array?
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};


int *ptr;


ptr = array + 4;





Now ptr points to the 5th element in the array (remembering element 1 is offset 0)


No comments:

Post a Comment