Suppose I have 2D array such as:
A[3][10];
Does it mean it is an array of 3 pointers? (from which everyone points to 1 of 10 elements)
So A is a pointer which points to 1 of 3 pointers?
Suppose I have 2D array such as:
A[3][10];
Does it mean it is an array of 3 pointers? (from which everyone points to 1 of 10 elements)
So A is a pointer which points to 1 of 3 pointers?
No.
It means it's an array of 3 arrays, where each of these is an array with 10 elements.
If it helps, you can think of it as one big 1D array of 30 elements with compiler support that allows you to use 2D indexing (the compiler performs the necessary calculations to turn your indexes into a flat index). In fact, this is actually how it is implemented.
No, it is not an array of 3 pointers. Look at the memory representation:
A[3][10]
=
|_|_|_|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|_|_|_| |_|_|_|_|_|_|_|_|_|_|
^ ^
px px+4
That is, A
is an array of 3 arrays which contains 10 elements each. These three arrays are contiguous in memory. That is, the element after A[0][9]
is A[1][0]
.
And of course, as chris said, don't confuse arrays with pointers.