Alex Wenger
Alex Wenger

Reputation: 19

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

Upvotes: 0

Views: 116

Answers (1)

sirbingo
sirbingo

Reputation: 31

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

Upvotes: 1

Related Questions