int *arr = new int(n);
does not create an array of int
s 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 int
s of size n
: it creates a single int on the heap, with value n
.
You want:
int *arr = new int[n];