【发布时间】:2015-07-28 09:52:22
【问题描述】:
#include <stdio.h>
int main(void)
{
int i;
int *p = (int *) malloc(5 * sizeof(int));
for (i=0; i<10; i++)
*(p + i) = i;
printf("%d ", *p++);
return 0;
}
所以,我运行了这段代码。现在我在这里被告知Why won't the output be 4 in this case?(在接受的答案中)*p++ 将首先增加指针然后取消引用它。因此,在上面的代码中,指针不应该先递增然后取消引用,因此输出应该是1吗?相反,输出结果为0。为什么?
【问题讨论】:
-
请see why not to cast
malloc()和C中的family返回值。 -
上述帖子中给出的答案大多是说我们必须编写不必要的代码,这与我的问题有什么关系?
-
你需要
#include <stdlib.h>
标签: c post-increment