Hi. Below is my c++ code. I am trying to create a 2D dynamic array which is created with the correct number of rows and columns. However, I can't seem to access row and column values above 4. Even sizeof(array) and sizeof(array[0]) both output 4.
1 2 3 4 5 6 7 8 9 10 11 12
int x;
int y = 5;
float** g_schedule;
int main(){
x = findSize();
g_schedule = newfloat* [x];
for (int row = 0;row < x;row++){
g_schedule[row] = newfloat[y];
}
}
g_schedule is a pointer so sizeof(g_schedule) will give you the size of a pointer. g_schedule[0] is also a pointer so sizeof(g_schedule[0]) will also give you the size of a pointer.
To know the size you need to keep track of it using variables.
Thank you Peter87 and kemort, works perfectly now. The example also made it that much more easier to test. I found it awkward that 4 was always the output, but did not interrogate my code further.