Array pointer arithmetic question

Posted by Konrad on Stack Overflow See other posts from Stack Overflow or by Konrad
Published on 2010-03-31T17:04:17Z Indexed on 2010/03/31 17:13 UTC
Read the original article Hit count: 311

Filed under:
|
|

Is there a way to figure out where in an array a pointer is?

Lets say we have done this:

int nNums[10] = {'11','51','23', ... };   // Some random sequence
int* pInt = nNums[4];                     // Some index in the sequence.

...

pInt++;      // Assuming we have lost track of the index by this stage.

...

Is there a way to determine what element index in the array pInt is 'pointing' to without walking the array again?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c