Dynamic arrays are allocated in C++ like this.
int *arr = new int(5);
int *arr = new int[5];
What is the difference between these ways? Or Are they exactly same?
Dynamic arrays are allocated in C++ like this.
int *arr = new int(5);
int *arr = new int[5];
What is the difference between these ways? Or Are they exactly same?
An array is only created when you use []
. If you are not using []
, then you are not creating an array.
int *arr = new int(5);
allocates a single int
and gives it the value of 5
.
int *arr = new int[5];
allocates an array of 5 int
's with no specified value in each element.