fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void fun(int *arr, int rows, int cols);
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. int arr[4][6];
  11. int x=0;
  12. for(int i=0; i<4; i++)
  13. {
  14. for(int j=0; j<6; j++)
  15. {
  16. arr[i][j] = x;
  17. x++;
  18. }
  19. }
  20.  
  21. fun(&arr[0][0], 4, 6);
  22.  
  23. system("PAUSE");
  24. return EXIT_SUCCESS;
  25. }
  26.  
  27. void fun(int *arr, int rows, int cols)
  28. {
  29.  
  30. for(int i=0; i<rows; i++)
  31. {
  32. for(int j=0; j<cols; j++)
  33. {
  34. cout << *(arr+i*rows+j) << " ";
  35. }
  36. cout << endl;
  37. }
  38.  
  39. cout << endl << endl;
  40. }
  41.  
Success #stdin #stdout 0.02s 5312KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 
4 5 6 7 8 9 
8 9 10 11 12 13 
12 13 14 15 16 17