Maybe this is a better approach:
Code:
#include <stdio.h>
#define LEN 4
// n = number of "lines", m = number of "columns".
// p pointer to the first element.
int sum_two_dimensional_array ( const int *p,
int n, int m )
{
int sum = 0;
// Points to next address beyond the array boundary.
const int *q = p + m*n;
while ( p < q )
sum += *p++;
return sum;
}
int main ( void )
{
int arr[][LEN] = {
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 0, 3, 2}
};
printf ( "The sum is: %d\n",
sum_two_dimensional_array ( (const int *)arr,
3, 4 ) );
return 0;
}