首页 > 解决方案 > C Void Pointer Inquiry - 不明白为什么我的代码没有按我的预期工作:(

问题描述

谁能向我解释为什么 printf("%d\n", (int *)p[0]) 不打印 10?

void *p[10] = {NULL};
int a = 10;
p[0] = &a;
printf("%d\n", (int *)p[0]);

标签: cpointers

解决方案


因为您将数组中的指针解释为指向 int ( (int *)p[0]) 的指针,而不是取消引用它,所以改为*(int *)p[0]


推荐阅读