Changes

Jump to: navigation, search

C/C++ FAQ

176 bytes added, 20:10, 8 November 2012
no edit summary
<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. For example an array[3][3] would looks something like this in memory '''|''' |||| '''|''' |||| '''|''' |||| '''|''' 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.
*Comment (pliu): Excellent question and explanation. We need to make a distinction between a STATIC 2-d array and a 2-d array that is created by DYNAMAC MEMORY ALLOCATION.<br>
<br>'''Submitted by:''' Team 6 <br><br>
----
1
edit

Navigation menu