27 lines
720 B
C
27 lines
720 B
C
#include <stdio.h>
|
|
|
|
int main()
|
|
{
|
|
int *arr[10]; // arr 数组用来存储地址,每个元素都是 int *
|
|
int a = 1, b = 2;
|
|
arr[0] = &a; // 将 a 的地址存放在 arr 数组的第一个元素中
|
|
arr[1] = &b;
|
|
|
|
a = a + b;
|
|
printf("arr[0] = %d\n", *arr[0]); // *arr[0] = 3
|
|
|
|
int arr2[3] = {10, 20, 30};
|
|
// 将 arr2 数组的第二个元素的地址存放在 arr 数组的第三个元素中
|
|
arr[2] = &arr2[1];
|
|
printf("arr[2] = %d\n", *arr[2]); // *arr[2] = 20
|
|
|
|
int *p = arr[2]; // arr[2] => int * => &arr2[1]
|
|
*p = 100;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
printf("%d ", arr2[i]); // 10 100 30
|
|
// printf("%d ", *(arr2 + i)); // 10 100 30
|
|
}
|
|
return 0;
|
|
} |