简体   繁体   English

为什么我的空int数组的C中的最后一个索引不返回0?

[英]Why is my empty int array not returning 0 for the last index in C?

int *ar[3];
int x;
for (x == 0; x < 3; ++x)
    printf("AR[%d]: %d\n", x, ar[x]);

this returns 这回来

AR[0]: 0 AR [0]:0

AR[1]: 0 AR [1]:0

AR[2]: 4196432 AR [2]:4196432

"int *ar[3]" means array of pointers, its element is a pointer to int, and there is no assignment for this array, that means its element might be any garbage. “ int * ar [3]”表示指针数组,它的元素是一个指向int的指针,并且对该数组没有赋值,这意味着它的元素可能是任何垃圾。 BTW, the type of ar[x] is pointer, if you want to print ar[x], you should use "%p" instead of "%d", otherwise there is a vast from %p to %d, and the value maybe is not you expect. 顺便说一句,ar [x]的类型是指针,如果要打印ar [x],则应使用“%p”而不是“%d”,否则从%p到%d的范围很大,并且价值也许不是您期望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM