fork download
  1. #include <algorithm>
  2. int main()
  3. {
  4. // set up arr1
  5. int *arr1 = new int[5]; // make array of 5 ints and set arr1 to point to it
  6.  
  7. // add data to arr1
  8. arr1[0] = 1;
  9. arr1[1] = 2;
  10. arr1[2] = 3;
  11. arr1[3] = 4;
  12. arr1[4] = 5;
  13.  
  14. // set up arr2
  15. int *arr2 = new int[10]; // make array of 10 ints and set arr2 to point to it
  16. // arr2 = arr1; // lose the array of 10 ints forever and set arr2 to point to array of 5 ints
  17. std::copy(arr1, arr1+5, arr2); // copy the contents of the array of 5 ints into the array of 10 ints
  18.  
  19. // add more values
  20. arr2[5] = 6;
  21. arr2[6] = 7;
  22. arr2[7] = 8;
  23. arr2[8] = 9;
  24. arr2[9] = 10;
  25.  
  26. delete[] arr1;
  27. delete[] arr2;
  28. }
  29.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty