Reset pointer address after being incremented several times

1

I have the following code

#include <stdio.h>
#define T_INT 5
int main(int argc, char *argv[]) {

    int v[T_INT],i;
    int *p = &v;


    /* Preenchendo o vetor*/
    for (i=0;i<T_INT;i++){
        v[i] = i;
    }

    /* Tentando ler com o ponteiro incrementando o endereço */
    for (i=0;i<T_INT;i++){

       printf("%d\n",(*p));
       (*p++);
       }

}

I know I could use [], but I'm opting to use it for academic reasons, how could I reset this pointer to home position?

  

Considering that I can not use the variable 'v' anymore because it can   is out of scope

    
asked by anonymous 26.02.2015 / 06:57

1 answer

3

Make a copy of the pointer before changing it; then resets to that copy

    int *pbak = p;                // copia de p
    for (i = 0; i < T_INT; i++) {
        printf("%d\n", *p);
        p++;
    }
    p = pbak;                     // resetando p
    
26.02.2015 / 10:50