shr3jn
shr3jn

Reputation: 615

Confusion on pointers in C

I'm learning C and now I'm having confusion in pointers. My question is, why doesn't printf("%d", *(i)); return the element instead of address while using multidimensional array??

#include <stdio.h>

int main()
{
    int i[2][2] = {{1,8},{2,9},{3, 4}};
    //int i[2] = {1,2,3};
    printf("%d", *(i));
    printf("\n%d", i);
}

Upvotes: 0

Views: 140

Answers (2)

r_ahlskog
r_ahlskog

Reputation: 1966

Because a multidimensional array is can be written as **i so you doing *(i) gives you the address of the first array.

Upvotes: 1

user541686
user541686

Reputation: 210755

Well, it's an array of arrays, so indexing/dereferencing it once gives you an array, which decays to a pointer...

Upvotes: 6

Related Questions