【问题标题】:Effect of *p = array[i]?*p = array[i] 的影响?
【发布时间】:2015-09-12 19:32:17
【问题描述】:

我看过一个类似的作业

*p = array[i];

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

【问题讨论】:

  • *p = array[i] 取消引用p 并将array[i] 处的内容分配给p 指向的任何内容
  • 谢谢,知道我没有误读那个片段,我感觉好多了。

标签: c arrays pointers variable-assignment


【解决方案1】:

您的问题不清楚,因为没有提供足够的详细信息。 正如在 cmets 中所说的 *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

【讨论】:

  • “您的问题不清楚,因为没有提供足够的详细信息”对不起,我会在以后的问题中提供更详细的信息。
  • 尽快点击发帖按钮。感谢你的回答。我以为是这样的,但此刻我在指针上感觉有点不稳定。这有帮助。
猜你喜欢
  • 1970-01-01
  • 2017-10-16
  • 2011-12-03
  • 2013-01-19
  • 2020-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-07
相关资源
最近更新 更多