the first line's declaring a variable of type int. I get that. |
No, it isn't. It's declaring a variable of type
int *
- that is, a pointer to an int; that is, a variable which stores a memory address, and treats the data held at that address as an int.
This is important;
int
is not the same type as
int *
.
is the new int variable newArray being transformed into an array[]. |
No. Line 4 is:
- dynamically allocating memory for the array on the heap
- storing the address of that array (or, more precisely, the address of the first element of the array) in the pointer variable called
newArray
.
EDIT: On line 2, you are declaring and initialising
newArray
, and on the very next line of code (line 4), you are changing it's value to something else. This is pointless; you should simply initialise it to the value you want it to actually be in a single line:
|
int *newArray{new int[size1 * size2]};
| |