I am trying to make an array which contains 1D arrays of varying length. Due to the variation in length, I cannot use a 2D array. My code is as follows:
int ROW = 6;
int COL = 4;
int faceverts[6][4] = {{3,2,1,0}, {4,5,1,0}, {2,6,5,1}, {2,3,5,6}, {7,3,0,4}, {1,6,7,4}};
int (*q)[4] = faceverts;
int main(){
for (int i = 0; i < ROW; i++){
for (int k = 0; k < COL; k++)
printf("%d ", *(*(q+i)+k));
printf("\n");
}
}
My goal is to be able to get rid of those ROW and COL variables, as well as not have a fixed 2D array, but rather an array of 1D arrays of varying length. I have been told that using pointers is key to doing this task, but I do not know how to do this myself.
Is it possible I can use pointers to multiple 1D arrays of varying length?. Arrays cannot "vary" in length once allocated either on the heap or on the stack. You can move pointers around / reallocate. But concept of "varying" an array length is not a thing.