I am having a tough time understanding the type and use of the name of the array in C. It might seems a long post but please bear with me.
I understand that the following statement declares a to be of type int [] i.e array of integers.
int a[30]; While a also points the first element of array and things like *(a+2) are valid. Thus, making a look like a pointer to an integer. But actually the types int [] and int* are different; while the former is an array type and later is a pointer to an integer.
Also a variable of type int [] gets converted into a variable of type int* when passing it to functions; as in C arrays are passed by reference (with the exception of the sizeof operator).
Here comes the point which makes me dangle. Have a look at the following piece of code:
int main() { int (*p)[3]; int a[3] = { 5, 4, 6 }; p = &a; printf("a:%d\t&a:%d\n",a,&a); printf("%d",*(*p + 2)); } OUTPUT:
a:2686720 &a:2686720 6 So, how does the above code work? I have two questions:
aand&ahave the same values. Why?- What exactly does
int (*p)[3];do? It declares a pointer to an array, I know this. But how is a pointer to an array different from the pointer to the first element of the array and name of the array?
Can anyone clarify things up? I am having a hell of a lot of confusions.
I know that I should use %p as a placeholder instead of using %d for printing the value of pointer variables. As using the integer placeholder might print truncated addresses. But I just want to keep things simple.

sizeofis not a function. It's an operator. The parens are not generally necessary. The reason they're needed forsizeof(int)is because(int)is a type. So, for example, if you haveint a[10], then you can use sizeof likesizeof a, without any parens.sizeofis not a function, see the C99 Standard, section 6.4.1, where it is listed as a keyword, and hence cannot be a function. See also section 6.5.3 (unary operators), and section 6.5.3.4 (The sizeof operator).awhen you declareint a[30]isn'tint []; it'sint [30]. The array length is part of the type.sizeof, even without checking the standard, you should be able to realize that sizeof couldn't possibly be a function. It is impossible to implement a function that does what sizeof does: not only is the information needed not available to a C function, but the answer is needed at compile time. Only the compiler itself can provide the result of sizeof.