使用C中的指针进行2D数组操作

假设我有一个操作2D数组的函数,该数组从主函数接收指向2D数组的指针作为其参数。

现在,我想修改(假设每个元素添加10个)2D数组的每个元素。

我有兴趣知道使用给我的单个指针遍历2D数组并返回新修改的数组的指针。

粗糙的结构

假设指针a包含2D数组的初始地址。

 int add_10(int *a) { int i, j, b[M][N] = {0}; for(i = 0; i < M; i++) for(j = 0; j < N; j++) b[i][j] = 10 + a[i][j]; } 

 int* add_10(const int *dest, const int *src, const int M, const int N) { int *idest = dest; memmove(dest, src, M * N * sizeof(int)); for(int i = 0; i < (M * N); ++i) *idest++ += 10; return dest; }