Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <typename T>
- void printArr(T* begin, T* end)
- {
- while (begin != end)
- {
- std::cout << *begin++ << ' ';
- }
- std::cout << '\n';
- }
- int main()
- {
- int arrSize{ 10 };
- int* arrSrc{ new int[10]{1,2,3,4,5,6,7,8,9,10} };
- //1,2,3,4,5,6,7,8,9,10
- //1,2,3,4,5,[42],6,7,8,9,10
- // arrSize == 11
- printArr(arrSrc, arrSrc + arrSize);
- auto newArr{ new int[++arrSize] };
- for (int i{ 0 }; i < arrSize - 1; ++i)
- {
- newArr[i] = arrSrc[i];
- }
- newArr[arrSize - 1] = 11;
- //delete[] arrSrc;
- arrSrc = newArr;
- printArr(arrSrc, arrSrc + arrSize);
- newArr = new int[--arrSize];
- for (int i{ 0 }; i < arrSize; ++i)
- {
- newArr[i] = arrSrc[i];
- }
- //delete[] arrSrc;
- arrSrc = newArr;
- printArr(arrSrc, arrSrc + arrSize);
- delete[] arrSrc;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement