A solution using type casting would be:
Code:
#include <stdio.h>
#define COLS 2
// or whatever you need
int main(void)
{
int arr1d[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int (*arr2d)[COLS] = (int (*)[COLS]) arr1d;
int i, j;
int a = 0; // for indexing into arr1d
int rows = sizeof(arr1d)/(sizeof(arr1d[0]) * COLS);
puts("Nr\tarr2d\t arr1d");
for (i = 0; i < rows; ++i)
for (j = 0; j < COLS; j++)
printf("%2d %p %p\n", arr2d[i][j], (void *) &arr2d[i][j], (void *) &arr1d[a++]);
return 0;
}
arr2d is a pointer to an array of COLS ints, i.e. it is a pointer to a row of your two dimensional array (with x rows and COLS columns).
The assignment on line 8 has the effect that it points to the beginning of your one dimensional array, thus you now treat the one dimensional array as an array with COLS columns and x rows (line 11 calculates the number of rows assuming that the one dimensional array has a multiple of COLS elements).
The rest is simple pointer arithmetic. arr2d[i] points to the ith row, thus arr2d[i+1] points to the ith + 1 row. Since arr2d is a pointer to an array with COLS ints, COLS elements of your one dimensional array are skipped.
The output will show you that you actually access the same element with both variables (arr1d and arr2d).
Bye, Andreas