fork download
  1. #include <iostream>
  2.  
  3. void printarray(int a[2][2])
  4. {
  5. printf("#####2D access... \n");
  6. for (int i = 0; i<2; i++)
  7. {
  8. for (int j = 0; j<2; j++)
  9. {
  10.  
  11. printf("## %p-->%d \n", &a[i][j], a[i][j]);
  12. }
  13. }
  14. }
  15.  
  16. void printarray(int b[4])
  17. {
  18. printf("#####1D access... \n");
  19. for (int i = 0; i<4; i++)
  20. {
  21. printf("## %p-->%d \n", &b[i], b[i]);
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. int a[4] = { 10,20,30,40 };
  28. int(&arr)[2][2] = reinterpret_cast<int(&)[2][2]>(a);
  29. printarray(arr);
  30.  
  31. int b[2][2] = {{ 10,20 },{ 30,40 }};
  32. int(&brr)[4] = reinterpret_cast<int(&)[4]>(b);
  33. printarray(brr);
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 4376KB
stdin
Standard input is empty
stdout
#####2D access... 
## 0x7fff708c4a90-->10 
## 0x7fff708c4a94-->20 
## 0x7fff708c4a98-->30 
## 0x7fff708c4a9c-->40 
#####1D access... 
## 0x7fff708c4aa0-->10 
## 0x7fff708c4aa4-->20 
## 0x7fff708c4aa8-->30 
## 0x7fff708c4aac-->40