The array parameter belongs to the pointer parameter.
Pointer parameter immediate address parameter (or reference parameter), this is the only way to modify the value of a parameter in a function.
If you take an array as an argument, whether you like it or not, it's a pointer to a pointer to the first value.
1. An array parameter is a pointer to the first element:
#include <stdio.h>
void getArr(int p[], int si);
int main(void)
{
int ns[] = {1,2,3,4,5};
getArr(ns, sizeof(ns)/sizeof(ns[0]));
getchar();
return 0;
}
void getArr(int p[], int si) {
int i;
for (i = 0; i < si; i++) {
printf("%d\n", p[i]);
}
}
2. Simply declare it directly as a pointer:
#include <stdio.h>
void getArr(int *p, int si);
int main(void)
{
int ns[] = {1,2,3,4,5};
getArr(ns, sizeof(ns)/sizeof(ns[0]));
getchar();
return 0;
}
void getArr(int *p, int si) {
int i;
for (i = 0; i < si; i++) {
printf("%d\n", p[i]);
}
}
3. Even if you specify a dimension in the parameter, it does not work:
#include <stdio.h>
void getArr(int p[2], int si);
int main(void)
{
int ns[] = {1,2,3,4,5};
getArr(ns, sizeof(ns)/sizeof(ns[0]));
getchar();
return 0;
}
void getArr(int p[2], int si) {
int i;
for (i = 0; i < si; i++) {
printf("%d\n", p[i]);
}
}