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 choosing to use it for academic reasons, as I could reset this pointer to initial position ?
whereas I can no longer use the variable 'v' as it can is out of scope
int *p = &v;
should beint *p = v;
. The type of&v
is(int*)[T_INT]
which is not compatible withint*
.– pmg