int (*p)[4] , *ptr;
int a[4] = {10,20,30,40};
printf(\"%p\\n%p\\n%p\",&a,a,&a[0]);
p = &a ;
//p=a; gives error
//ptr = &a; gives error
ptr
Both answers have been cleared through these discussions. I would like to conclude them :
1. What is the difference between int *ptr and int *ptr[4];
Answer : Both of the pointer variables are same in size because both of them hold addresses only. It is just a conceptual difference that ptr holds the address of an integer. Well, ofcourse you can use it to point to the starting location of the array. But what this says the compiler is : It can hold any integer. When you try to do "ptr++" in your code, it will just shift the memory address 1 unit ahead(according to whatever bytes are reserved for an integer for that system). But, int *ptr[4] says that, ptr is a pointer that points to an entire whole array with only the starting location stored. Well, ofcourse ptr's in both cases store the same address. But when you try to do "ptr++" in this case, it will shift to 4 units ahead, because compiler interprets this as a pointer of an array, rather than a pointer of integer.
2. Why ptr=&a works and ptr =&a[0] or ptr=a doesn't work even if these all values are same ?
Answer : ptr=a and ptr=&a both are conceptually right. But, compiler works on strict rules. If you wanted to say that ptr contains address of an integer, well it should be assigned that way which is ptr = a OR ptr=&a[0] (denoting the assigned space is an integer). While, if ptr is declared to be the address of an array, ptr = &a[0] pr ptr = a is interpreted by compiler as this ptr getting the address of an integer, which is not true because ptr here denotes the address of an array. It should not hold address of an integer in this case. So, p=&a looks syntactically very right to compiler. Thus, this is the only option it accepts.
:)