avr39-ripe

dyn2dArray

May 8th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9.     int y = 4, x = 5;
  10.     int** ptr = new int*[y];
  11.     int* tmpPtr = new int[y*x] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
  12.  
  13.     for (int i=0; i < y; i++)
  14.     {
  15.         ptr[i]=tmpPtr + (x * i);
  16.     }
  17.  
  18.     for (int i=0; i < y; i++)
  19.     {
  20.         for (int j=0; j< x; j++)
  21.         {
  22.             cout << ptr[i][j] << " ";
  23.         }
  24.         cout << endl;
  25.     }
  26.  
  27.     delete[] tmpPtr;
  28.     delete[] ptr;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment