*(ptr+i) is equal to ptr[i] and *(ptr+1) - ptr[1] .
You may think that a 2-dimensional array is an array of an array.
ptr points to a full 2-dimensional array, so ptr+1 points to the next 2-dimensional array.
In the picture below ptr displays 2-D and the number of columns is 3
The original figure made by Mr. Kerrek S.B., here , you should also check!
+===============================+==============================+==== |+---------+----------+--------+|+----------+---------+--------+| ||ptr[0,0] | ptr[0,1] | ptr[0,2]|||ptr[1,0] |ptr[1,1] | ptr[1,2]|| ... |+---------+----------+--------+++----------+---------+--------++ ... | ptr[0] | ptr[1] | +===============================+===============================+==== ptr
*(*ptr+1) = *( ptr[0] + 1 ) = ptr[0][1]
Understand the following:
ptr indicates the completion of 2-D.
*ptr = *(ptr + 0) = ptr[0] This is the first line.
*ptr + 1 = ptr[1] means the second line
*(*ptr+1) = *(*(ptr + 0) + 1 ) = *(ptr[0] + 1) = ptr[0][1]
Array 0 Elements: 1 2 3 4
And the output of GDB:
(gdb) p *(*ptr+1) $1 = 2
which is true 2 , this can be read using ptr[0][1] .
source share