使用 memcpy 进行二维数组赋值

 1 #include <stdio.h>
 2 #include <string.h> 
 3 
 4 
 5 
 6 char array1[3][2] = {{1, 2}, {3, 4}, {5, 6}};
 7 
 8 int main()
 9 {
10     char i;
11     char temp[3][2];
12     char temp1[2][2][2];
13     
14     memcpy(temp, array1, 6);
15     memcpy(temp1, array1, 6);    
16 
17     for(i =0; i <6; i++)
18     {
19         printf("%d, ", temp[0][i]);
20     }
21     printf("\n");
22     for(i =0; i <6; i++)
23     {
24         printf("%d, ", temp1[0][0][i]);
25     }
26     printf("\n");
27 }

 

相关文章:

  • 2021-11-17
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-07-21
猜你喜欢
  • 2021-10-25
  • 2021-12-16
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案