Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- void printArr(int* ptr, int size)
- {
- for (auto elP{ ptr }; elP != (ptr + size); ++elP)
- {
- std::cout << *elP << ' ';
- }
- std::cout << '\n';
- }
- void copyArr(int* arr1, int* arr2, int arr2Size)
- {
- for (auto elP{ arr2 }; elP != (arr2 + arr2Size); *arr1++ = *elP++);
- }
- int main()
- {
- int* ptr{ nullptr };
- int size{ 5 };
- ptr = new int[size]{ 1,2,3,4,5 };
- printArr(ptr, size);
- size = 10;
- int* tmp = new int[size]{};
- copyArr(tmp, ptr, 5);
- delete[] ptr;
- ptr = tmp;
- printArr(ptr, size);
- size = 4;
- tmp = new int[size] {};
- copyArr(tmp, ptr, 4);
- delete[] ptr;
- ptr = tmp;
- printArr(ptr, size);
- delete[] ptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement