fork download
  1. #include <iostream>
  2.  
  3. int *changeSize(int m[], int basicSize, int desiredSize) {
  4. int *newArray = new int[desiredSize];
  5. for (int i = 0; i<basicSize && i<desiredSize; i++) {
  6. newArray[i] = m[i];
  7. }
  8. return newArray;
  9. }
  10.  
  11. int main()
  12. {
  13. int i;
  14.  
  15. int *m = new int[123];
  16.  
  17. m[0] = 12;
  18. m[1] = 22;
  19. m[2] = 33;
  20.  
  21. std::cout << "m[2] before " << m[2] << std::endl;
  22. std::cout << "And we can't access elem 220" << std::endl;
  23.  
  24. m = changeSize(m, 123, 222);
  25.  
  26. m[2] = 99;
  27. std::cout << "m[2] after " << m[2] << std::endl;
  28.  
  29. m[220] = 32;
  30. std::cout << "And we can access elem 220. Now it is " << m[220] << std::endl;
  31. std::cin >> i;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
m[2] before 33
And we can't access elem 220
m[2] after 99
And we can access elem 220. Now it is 32