fork download
  1. #include <memory.h>
  2. #include <stdio.h>
  3.  
  4. struct SomeArray {
  5. int index;
  6. char randompadding[5];
  7. };
  8.  
  9. int main() {
  10. const int XSIZE = 10;
  11. const int YSIZE = 10;
  12. SomeArray arr[XSIZE * YSIZE];
  13. SomeArray arr2d[XSIZE][YSIZE];
  14. int counter = 1;
  15.  
  16. ::memset(arr, 0, sizeof(arr));
  17.  
  18. for (int y = 0; y < YSIZE; y++) {
  19. for (int x = 0; x < XSIZE; x++) {
  20. arr[XSIZE*y + x].index = counter++;
  21. }
  22. }
  23.  
  24. ::memcpy(arr2d, arr, sizeof(arr));
  25.  
  26. for (int x = 0; x < XSIZE; x++) {
  27. for (int y = 0; y < YSIZE; y++) {
  28. printf("%d\n", arr2d[x][y].index);
  29. }
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100