With a dynamic 2D array:
int *arr;
arr = int *calloc(maxrow*maxcol, sizeof(int));
how do you reference the different elements (alternate notation arr[row][col] will not compile). Is pointer arithmetic the solution?
This is a discussion on dynamic 2D array question within the C Programming forums, part of the General Programming Boards category; With a dynamic 2D array: int *arr; arr = int *calloc(maxrow*maxcol, sizeof(int)); how do you reference the different elements (alternate ...
With a dynamic 2D array:
int *arr;
arr = int *calloc(maxrow*maxcol, sizeof(int));
how do you reference the different elements (alternate notation arr[row][col] will not compile). Is pointer arithmetic the solution?
Then you can use arr[row][col] notationCode:int **arr; arr = malloc( maxrow * sizeof(int*) ); for ( i = 0 ; i < maxrow ; i++ ) arr[i] = calloc( maxcol, sizeof(int) );
Awesome. Thanks Salem.