user-0 提问: c语言中，把二维数组复制到另一个二维数组，用指针表示法，如何复制？

回复:
user: user-1
content: 内存空间是连续分配的 既然用指针处理，memcpy 即可，为什么还要写这么多循环，效率太低

user: user-0
content: 引用 3 楼 自信男孩 的回复：#include <stdio.h>  #define three 3  void copy_arr2(int (*target)[5],int (*source)[5],int n); void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]); void put(int (*target)[5],int n);  int main()  {      int source[three][5] =      {          {1, 2, 3, 4, 5},          {6, 7, 8, 9, 10},          {11, 12, 13, 14, 15}      };      int target2[three][5];      int target3[three][5];       copy_arr2(target2,source,three);      printf("\ntarget2= ");      put(target2,three);      copy_arr3(target3,source,source+three);      printf("\ntarget3= ");      put(target3,three);  /*      printf("\ntarget2= ");      put(target2,three);      printf("\ntarget3= ");      put(target3,three); */      return 0;  }  void copy_arr2(int (*target)[5],int (*source)[5],int n) {     int (*s)[5],*v, (*d)[5], *z;      for (s = source, d = target; s < source + n; s++, d++) {         for (v = *s, z = *d; v < *s + 5; v++, z++)             *z = *v;     }     /*     for (u=source; u<source+n; u++,target++)     {         for(v=*u; v<*u+5; v++,*target++)         {             **target = *v;         }     }     */ }  void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]) {     int *v, *d;     while (source < end) {         for (v = *source, d = *target; v < *source+5; v++, d++)             *d = *v;          target++;         source++;     }     /*     for (; source<end; target++,source++)     {         for (; *source<*end; *target++,*source++)             **target   = **source;     }     */ }  void put(int (*target)[5],int n) {     int u,v;     for (u=0; u<n; u++)     {         for (v=0; v<5; v++)         {             printf("%2d  ",target[u][v]);         }         printf("\n");     } }  供参考～  还是要理解int (*target)[5];指针，target++是偏移了5* sizeof(int)个字节～谢谢大佬，我现在彻底理解了

user: user-0
content: 引用 1 楼 寻开心 的回复：void copy_arr2(int (*target)[5],int (*source)[5],int n) { 	int * pS = source[0]; 	int * pT = target[0]; 	int i = 0; 	for ( i=0; i<5*n; i++)          	*pT++ = *pS++; };  你没有理解二维数组下的指针++的意思 你自己把u++ 结果输出看看什么吧非常感谢，您的回答对我太有帮助了

user: user-0
content: 谢谢你们，我搞懂了

user: user-2
content: 看你自己另外提问的那个帖子， 核心问题是 *taget++上 这个执行结果是target++ 然后取*地址 比不是你想象的（*target）++ 因为（*target）不是一个变量，++加不出东西来

user: user-0
content: 引用 3 楼 自信男孩 的回复：#include <stdio.h>  #define three 3  void copy_arr2(int (*target)[5],int (*source)[5],int n); void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]); void put(int (*target)[5],int n);  int main()  {      int source[three][5] =      {          {1, 2, 3, 4, 5},          {6, 7, 8, 9, 10},          {11, 12, 13, 14, 15}      };      int target2[three][5];      int target3[three][5];       copy_arr2(target2,source,three);      printf("\ntarget2= ");      put(target2,three);      copy_arr3(target3,source,source+three);      printf("\ntarget3= ");      put(target3,three);  /*      printf("\ntarget2= ");      put(target2,three);      printf("\ntarget3= ");      put(target3,three); */      return 0;  }  void copy_arr2(int (*target)[5],int (*source)[5],int n) {     int (*s)[5],*v, (*d)[5], *z;      for (s = source, d = target; s < source + n; s++, d++) {         for (v = *s, z = *d; v < *s + 5; v++, z++)             *z = *v;     }     /*     for (u=source; u<source+n; u++,target++)     {         for(v=*u; v<*u+5; v++,*target++)         {             **target = *v;         }     }     */ }  void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]) {     int *v, *d;     while (source < end) {         for (v = *source, d = *target; v < *source+5; v++, d++)             *d = *v;          target++;         source++;     }     /*     for (; source<end; target++,source++)     {         for (; *source<*end; *target++,*source++)             **target   = **source;     }     */ }  void put(int (*target)[5],int n) {     int u,v;     for (u=0; u<n; u++)     {         for (v=0; v<5; v++)         {             printf("%2d  ",target[u][v]);         }         printf("\n");     } }  供参考～  还是要理解int (*target)[5];指针，target++是偏移了5* sizeof(int)个字节～您的回复很漂亮，您说的理解二级指针我确实懂了，但是可能我头脑没反应过来，我并没有发现我的原代码具体错在哪，您能解释得详细一点吗？十分感谢！

user: user-3
content: #include <stdio.h>  #define three 3  void copy_arr2(int (*target)[5],int (*source)[5],int n); void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]); void put(int (*target)[5],int n);  int main()  {      int source[three][5] =      {          {1, 2, 3, 4, 5},          {6, 7, 8, 9, 10},          {11, 12, 13, 14, 15}      };      int target2[three][5];      int target3[three][5];       copy_arr2(target2,source,three);      printf("\ntarget2= ");      put(target2,three);      copy_arr3(target3,source,source+three);      printf("\ntarget3= ");      put(target3,three);  /*      printf("\ntarget2= ");      put(target2,three);      printf("\ntarget3= ");      put(target3,three); */      return 0;  }  void copy_arr2(int (*target)[5],int (*source)[5],int n) {     int (*s)[5],*v, (*d)[5], *z;      for (s = source, d = target; s < source + n; s++, d++) {         for (v = *s, z = *d; v < *s + 5; v++, z++)             *z = *v;     }     /*     for (u=source; u<source+n; u++,target++)     {         for(v=*u; v<*u+5; v++,*target++)         {             **target = *v;         }     }     */ }  void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]) {     int *v, *d;     while (source < end) {         for (v = *source, d = *target; v < *source+5; v++, d++)             *d = *v;          target++;         source++;     }     /*     for (; source<end; target++,source++)     {         for (; *source<*end; *target++,*source++)             **target   = **source;     }     */ }  void put(int (*target)[5],int n) {     int u,v;     for (u=0; u<n; u++)     {         for (v=0; v<5; v++)         {             printf("%2d  ",target[u][v]);         }         printf("\n");     } }  供参考～  还是要理解int (*target)[5];指针，target++是偏移了5* sizeof(int)个字节～

user: user-4
content: memcpy GG  重叠就 memmove 二维二什么维啊 降维打击

user: user-2
content: void copy_arr2(int (*target)[5],int (*source)[5],int n) { 	int * pS = source[0]; 	int * pT = target[0]; 	int i = 0; 	for ( i=0; i<5*n; i++)          	*pT++ = *pS++; };  你没有理解二维数组下的指针++的意思 你自己把u++ 结果输出看看什么吧