Say I create an array of pointers like so:
char ** arr[]
My understanding says this creates an array of pointers, each pointer points to an array of chars.
Then I want to set 8 such arrays for example, each array having 10 chars in it, so I do this:
arr = new char*[7];
for(int i = 0; i<9; i++)
arr[i] = new char[0];
this works, but my issue is I can't wrap my mind behind how it works.
In my mind when I write arr = new char*[7];
that means my array of pointers will have room for 7 pointers, but in actuality all 8 pointers work fine for me so I don't understand why putting 7 there works, whereas putting 6 for example crashes the program.
and then there's arr[i] = new char[0];
which again confuses me, cause to me that seems as if I'm creating arrays that can only contain 0 chars, yet when I try to input a 9 char string using strcpy
it works fine.
Does the new function automatically resize the arrays? is there something else here I'm simply not understanding?