I am a bit confused in accessing elements in an array of pointers. Say I have an pointer int **score_cards and it points to an array of int pointers of size n. I want to find the sum of the integers pointed to by the elements of the array.
I was thinking of doing:
int sum = 0;
int i;
for(i = 0;i<n;i++){
sum = sum + *(*score_card+ i);
}
But this is wrong, while, the following is right:
int sum = 0;
int i;
for(i = 0;i<n;i++){
sum = sum + *(*(score_card + i));
}
Now, I have two questions, since *score_cards points to the first element of the array, isn't the ith element *score_cards + i? i.e the address of the first element + i? Also, why do we increment i by 1, and not sizeof(*int) ? Thanks in advance!
a[b]is defined to be equal to*(a + b).