fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n = 10, m = 5;
  8. int *arrA = new int[n] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
  9. int *arrB = new int[m] {-1, -2, -3, -4, -5};
  10. for (int i = 0; i < n; i++)
  11. cout << arrA[i] << " ";
  12. cout << endl;
  13. for (int i = 0; i < m; i++)
  14. cout << arrB[i] << " ";
  15. cout << endl;
  16.  
  17. int** array_2d = new int*[2];
  18. swap(array_2d[0], arrA);
  19. swap(array_2d[1], arrB);
  20.  
  21. for (int i = 0; i < n; ++i)
  22. cout << array_2d[0][i] << " ";
  23.  
  24. cout << "\n";
  25. for (int i = 0; i < m; ++i)
  26. cout << array_2d[1][i] << " ";
  27.  
  28. for (int i = 0; i < 2; ++i) {
  29. delete[] array_2d[i];
  30. }
  31. delete[] array_2d;
  32. }
Success #stdin #stdout 0s 4260KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 0 
-1 -2 -3 -4 -5 
1 2 3 4 5 6 7 8 9 0 
-1 -2 -3 -4 -5