How do pointers work with arrays? I find the syntax a bit of a mystery, example (16x1):
int* a = new int[16];
a[16] = 33;
cout << a[16] << endl;
The above example works. Usually * needs to be in front of a pointer to write/read the value, but not with vectors?
The case is more complicated for multidimensional arrays, which I found the following a way to create (16x3):
int** a = (int**)new int[16];
for (int i = 0; i < 16; i++)
{
a[i] = (int*)new int[3];
}
a[15][2] = 4;
cout << a[15][2] << endl;
Again, the above works, but it's hard to grasp how the syntax relates to pointers. The syntax also works with malloc. With malloc there is an option "memset" which automatically initializes the multidimensional array (put in the for loop). Is there similar option with new?