Hello,
I have a 2 dimensional array dynamically allocated in my C code, in my function main. I need to pass this 2D array to a function. Since the columns and rows of the array are run time variables, i know one way to pass it is :
-Pass the rows,column variables and the pointer to that [0][0] element of the array
myfunc(&arr[0][0],rows,cols)
then in the called function access it as a 'flattened out' 1D array like:
ptr[i*cols+j]
But i don't want to do it that way, because that would mean a lot of change in code, since earleir, the 2D array passed to this function was statically allocated with its dimensions known at compile time.
So how can i pass a 2D array to a function and still be able to use it as a 2D array with 2 indexes like
arr[i][j].
Any pointers(pun intended) will be helpful.
Thank You,
-AD.