Home > Article > Backend Development > How to Pass a Two-Dimensional Array Reference to a Function in C ?
Passing a Two-Dimensional Array Reference to a Function in C
You're attempting to pass a reference to a two-dimensional array in C . The issue arises because your function prototype has syntax errors, specifically the "&" before "". This error indicates a missing comma or ellipsis before the "".
To correct this:
void do_something(int (&array)[board_width][board_height]);
This declares array as a reference to the two-dimensional array, allowing you to access and modify its elements directly.
void do_something(int array[board_width][board_height]);
However, this will pass a pointer to the first sub-array of the two-dimensional array. The compiler will ignore the "board_width" dimension, which may not be desirable if you require direct access to all elements.
The above is the detailed content of How to Pass a Two-Dimensional Array Reference to a Function in C ?. For more information, please follow other related articles on the PHP Chinese website!