How to change my array to dynamic

So this is the code I have so far, I didn't know it had to be a dynamic array so how would I Utilize dynamic array allocation to size the modal array


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;
int main()
{

 const int arraySize = 25;
 const int patternSize = 10;

 

 int arr1[arraySize] = {0,1,2,3,4,5,6,7,8,9};

 for(int i=0; i<arraySize; i++)
 {	 
	 cout << arr1[i%patternSize] << " ";

 }
	

	system("PAUSE");
	return 0;
}
closed account (N36fSL3A)
Vectors or pointers. Pointers are simple.
1
2
3
4
5
6
7
unsigned int size = 0;
std::cin >> size; // Get desired size

int* arr1 = new int[size];

// When you do whatever, be sure to delete it.
delete[] arr1;
Last edited on
Topic archived. No new replies allowed.