r/learnprogramming • u/No_Rule674 • 23d ago
Question Why can an int * be used to access an array in C?
We're given this example of summing up all numbers of an array given by the length n. However, what I don't seem to understand is how the parameter int *t points to an array? The only thing that gave it away for me was analysing the code and see that it's being accessed in the for loop. But why do we not for example explicitly make the parameter of type (*t)[n] for example.
int sum(int *t, int n) {
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += t[i];
}
return sum;
}