Open main menu

CDOT Wiki β

Changes

C/C++ FAQ

37 bytes added, 18:38, 8 November 2012
C/C++ FAQ
Submitted by Team42
<br><br>
'''Q:''' What is the correct way to pass a 2D array (called array) into a function? Which of the following is right: array[][], array[][COLS] or **array?
<br>
'''A:''' Any of the stated syntaxes are acceptable for passing a 2D array into a function. Generally the 2nd syntax (array[][COLS]) is used if the array is static and the number of cols is known. This is in order to reveal the preferred structure to the compiler, since the compiler stores a 2D array as one really long array with arrays as its elements. It For example an array[3][3] would looks something like this in memory '''|''' |||| '''|''' |||| '''|'''|||| '''|''' . Where where as we perceive the structure as a table. The other 2 syntaxes are equivalent and are generally used to pass a 2D array into a function if the structure is not know, hence for dynamic created arrays.
<br>'''Submitted by:''' Team 6 <br><br>
----