*p = array[i] 的影响?

Effect of *p = array[i]?

我看过一个类似于

的作业
*p = array[i];

在代码库中,我想知道这对指针有什么影响。如果之前有人问过这个问题,我深表歉意,但搜索引擎一直在吃掉我的特殊字符,可能妨碍了我的搜索。

您的问题不清楚,因为没有提供足够的详细信息。 正如评论中所说 *p = array[i] 取消引用 p 并将 array[i] 处的内容分配给 p 指向的任何内容。

示例 1

int i = 0, j;
int *p = &j; // p is a pointer to integer and now it points to j
int array[2] = { 4, 2 };
*p = array[i]; // this means j = array[0] so j = 4 and j is 4 now

示例 2

int i = 0, *j, k, l;
int **p = &j; // p is a pointer to pointer to integer and now it points to j
int* array[2] = { &k, &l };
*p = array[i]; // this means j = array[0] so j = &k and j points now to k