How to pass a 2D array as a parameter in C ?

A one dimensional array can be easily passed as a pointer, but syntax for passing a 2D array to a function can be difficult to remember. One important thing for passing multidimensional arrays is, first array dimension does not have to be specified. The second (and any subsequent) dimensions must be given or using single or double pointer. According to my opinion pointer is best way if you can deal with it properly. 

Method 1 – When second dimension is known




Drawback :- The above method is fine if second dimension is fixed and is not user specified

Method 2 –  Using Single Pointer




Method 3 –  Using an array of pointers or double pointer



 If you like this Article, then don’t forget to Click on Social likes buttons.