Smart pointers (from #include <memory>) eliminate manual new/delete:
auto p = make_unique<int>(42);
cout << *p; // 42
// Memory freed automatically when p leaves scope!
auto q = move(p); // transfer ownership; p is now null
auto a = make_shared<int>(100);
auto b = a; // both own the memory
cout << a.use_count(); // 2
b.reset();
cout << a.use_count(); // 1
// Memory freed when the last shared_ptr is destroyed
Write makeRange(int from, int to) returning a unique_ptr<vector<int>> with all integers from from to to inclusive.
Click "Run" to execute your code.