Changes

Jump to: navigation, search

C/C++ FAQ

857 bytes added, 19:31, 8 November 2012
C/C++ FAQ
Submitted by Team42
<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 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.
<br>'''Submitted by:''' Team 6 <br><br>
----

Navigation menu