主要是针对于数组访址的方式展开研究:
void fun(int arr[], int n)
{
int i = 0;
for (i = 0; i < n; i++)
{
printf("%d\t", arr[i]);
}
}
void fun1(int *arr, int n)\
{
int i = 0;
for (i = 0; i < n; i++)
{
printf("%d\t", *(arr + i));
}
}
void fun2()
{
int arr[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int i = 0;
int j = 0;
printf("\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
}
void fun3()
{
int arr[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int i = 0;
int j = 0;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\t", *(*(arr + i) + j));
}
printf("\n");
}
}
void fun4()
{
int arr1[] = { 1, 2, 3 };
int arr2[] = { 4, 5, 6 };
int arr3[] = { 7, 8, 9 };
int *arr[] = { arr1, arr2, arr3 };
int i = 0;
int j = 0;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)\
{
printf("%d\t", *(*(arr + i) + j));
}
printf("\n");
}
}
int main()
{
int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int sz = sizeof(arr) / sizeof(arr[0]);
fun(arr,sz);
printf("\n");
fun1(arr, sz);
printf("\n");
fun2();
printf("\n");
fun3();
printf("\n");
fun4();
printf("\n");
return 0;
}
结果理想: