If I have a vector of pointers of type *p[tamanho]
, where each position will be occupied by p[tamanho] = malloc(10*sizeof(int))
, how do I access each position of that vector allocated with malloc
?
If I have a vector of pointers of type *p[tamanho]
, where each position will be occupied by p[tamanho] = malloc(10*sizeof(int))
, how do I access each position of that vector allocated with malloc
?
How about this?
int i, j;
for (i = 0; i < tamanho; i++) {
for (j = 0; j < 10; j++) {
printf("%d ", p[i][j]);
}
}
Note that in the first pair of brackets, we access a position in the array, which results in a pointer. With the second pair of brackets, we access the position of the array from the resulting pointer.