简体   繁体   中英

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[1]: 0

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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