No way. It is not an ARRAY, it is a pointer to array of 3 integer.
You can allocate an array where each element will be array of 3 integer. This way you can allocate 2 dim array by one call to malloc (second dimension will be fixed).
int (*p)[3] = NULL;
p=malloc (10 * sizeof (int[3]));
will allocate array 10x3.
p[9][2] = 1;
Very useful if you are going to store array of string with fixed lenght, XYZ coordinates of points, etc.
Or even like that:
int (*p)[2][3][5] = NULL;
It is going to be 4 dim array.....
int (*p)[3]
p is a pointr to array of size 3.
p--> |2|5|6|1|
>> here one advantage of having pointer to array is that u can change the address of p pointing to some other array of int. but in general
int p[3]
u cant change the address.
int *p; pointer to int
int *p[10]; array[10] of pointers to int (not same as a 2D array)
int (*p)[10]; pointer to array[10] of int
int *p(); function returning pointer to int
int (*p)(); pointer to function returning int
int *(*p)(); pointer to function returning pointer to int
int (*p[])(); array[] of pointers to function returning int
int (*(*p())[5])(); function returning pointer to array[5] of pointers to function returning int
If you find yourself confused, believe me you are not the first in the world. But go through the above again keeping in mind the precedence and associativity of operators:
() [] {left to right}
* {right to left}
Finally if you can tell what the following is:
int *((*(*p[5])()))[10]
you can assume safely that you are a lot less confused.X-)
In case you were wondering, the declaration
int *((*(*p[5])()))[10];
makes p an array[5] of pointers to function returning pointer to array[10] of pointers to int.
Hope we all agree .
In case you have a different answer, or if you want a nice and easy way to come to the above correct conclusion go to faq205-924.
Its correct.
To simply int *p[10] means that you have 10 pointers pointing to integers. Since each of these are pointers (like p[0], p[1], etc), they can in turn point to a single number or an array of numbers.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.