How to tell where I am in an array with pointer arythmetic?

Posted by klez on Stack Overflow See other posts from Stack Overflow or by klez
Published on 2010-04-05T14:38:42Z Indexed on 2010/04/05 14:43 UTC
Read the original article Hit count: 227

Filed under:
|

In C, I have declared a memory area like this:

int cells = 512;
int* memory = (int*) malloc ((sizeof (int)) * cells);

And I place myself more or less in the middle

int* current_cell = memory + ((cells / 2) * sizeof (int));

My question is, while I increment *current_cell, how do I know if I reached the end of the allocated memory area?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers