int *arr = new int(n);
does not create an array of ints of size n: it creates a single int on the heap, with value n.
You want:
int *arr = new int[n];
1 Like
int *arr = new int(n);
does not create an array of ints of size n: it creates a single int on the heap, with value n.
You want:
int *arr = new int[n];