fork download
  1. #include <iostream>
  2.  
  3. template<typename T, std::size_t N, std::size_t M>
  4. void increment_2D(T (&a)[N][M])
  5. {
  6. for(std::size_t n = 0; n < N; ++n)
  7. for(std::size_t m = 0; m < M; ++m)
  8. ++a[n][m];
  9. }
  10.  
  11. int main()
  12. {
  13. int a[3][3] = {1,2,3,4,5,6,7,8,9};
  14. increment_2D(a);
  15. for(auto& r: a) {
  16. for(int n: r)
  17. std::cout << n << ' ';
  18. std::cout << '\n';
  19. }
  20. }
  21.  
  22.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
2 3 4 
5 6 7 
8 9 10