fork(1) download
  1. #include<iostream>
  2.  
  3. template <class T>
  4. void foo()
  5. {
  6. int N = 10;
  7. int M = 2;
  8. T a[] = { 2,1,4,3,6,5,8,7,10,9 };
  9.  
  10. T(*b)[5] = (T(*)[5]) a;
  11. for (int i = 0; i<M; i++) {
  12. for (int j = 0; j<N / M; j++) {
  13. std::cout << b[i][j] << ' ';
  14. }
  15. std::cout << '\n';
  16. }
  17. std::cout << '\n';
  18. }
  19.  
  20.  
  21.  
  22. int main() {
  23. foo<int>();
  24. foo<short>();
  25. foo<float>();
  26. foo<double>();
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2 1 4 3 6 
5 8 7 10 9 

2 1 4 3 6 
5 8 7 10 9 

2 1 4 3 6 
5 8 7 10 9 

2 1 4 3 6 
5 8 7 10 9