c++ - What is difference between int (*p)[3] and int *p[3]? -
this question has answer here:
i totally understand "int *p[3]
" ( p array of 3 pointer meaning can have 3 different rows of number of ints allocating memory our size of different rows).
my confusion lies " int (*p)[3]
" signifies? "p" stores address of 3 contiguous memory of int or else?
please clarify , how use use in program distinguish them.
thanks lot in advance.
@revised
sorry putting duplicate question. didn't search doubt intensively. doubt still remains novice programmer. went through both pages of q/a c pointer array/array of pointers disambiguation
and
second link partly clears doubt eliminate doubt please explain above question in reference stack , heap: example
int *p[3]; // (1)
take 12(3*4bytes) bytes of stack , heap depend on run-time.
int (*p1)[3]; //(2)
(2) using "new" 1
p1 = new int[7][3]; // (3)
given in 1 of answer of link int (*p) [4]? ; question since " int (*p1)[3]; //(2) " pointer array of 3 ints how memory taken p1 @ compile time eq(3) can replaced
p1 = new int[n][3]; // (3) n integer
so then?
please explain.
int *p[3]; // type of p int *[3]
declares p
array 3 of int *
(i.e., array of 3 int *
)
and
int (*p)[3]; // type of p int (*)[3]
declares p
pointer array 3 of int
(i.e., pointer array of 3 int
)
Comments
Post a Comment