Advertisement
avr39ripe

kirilPtrTask

Jan 4th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. void print(T* begin, T* end)
  5. {
  6.     while (begin != end)
  7.     {
  8.         std::cout << *begin << ' ';
  9.         ++begin;
  10.     }
  11.     std::cout << '\n';
  12. }
  13.  
  14. int main()
  15. {
  16.     int arrSize{ 10 };
  17.     int* ptr{ nullptr };
  18.    
  19.     ptr = new int[arrSize] {1,2,3,4,5,6,7,8,9,10};
  20.  
  21.     print(ptr, ptr + arrSize);
  22.     // 15
  23.  
  24.  
  25.     delete[] ptr;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement