#include <iostream>
#include <new>
int main()
{
int size = 5;
int *arr = newint[size]; //dynamically allocating memory for your array of ints
// The rest of the code
delete[] arr;
return 0;
}
EDIT: Yup, I had forgotten to use delete[]. Added it in the code. Whenever you dynamically allocate anything, you must always deallocate it in the end when you don't need it anymore.
#include <iostream>
#include <new>
int main()
{
int size = 5;
int *arr = newint[size]; //dynamically allocating memory for your array of ints
// The rest of the code
delete[] arr;
return 0;
}
#include <vector>
int main()
{
int size = 5;
std::vector<int> arr (size); // object that manages an array of ints
// The rest of the code
return 0;
}
The "smart pointer" object:
1 2 3 4 5 6 7 8
#include <memory>
int main()
{
int size = 5;
auto arr = std::make_unique<int[]>(size); // object that manages an array of ints
// The rest of the code
return 0;
}