In order to do pointer arithmetic the pointer has to know the size of what it is pointing to.
int test_arr[2][4];
is equivalent to 2 elements of type int[4]
. So whenever you add 1 to the pointer, it will jump the size of 4 integers. If you had int*
it would increment the size of a single integer only.
Like said in the comments, what you want is: int (*ptr_array)[4] = test_arr;
I know, the syntax is a little weird, but that's how you do it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…