One-dimensional array
Function definition
There are four ways a function definition:
One way:
void testfunc(int a[], int size)
Second way:
void testfunc(int* a, int size)
Three ways:
void testfunc(int a[10], int size)
Four ways:
template<class T>
void testfunc(T a, int size)
Way five:
template<class T>
void testfunc(T& a, int size)
The first four way, in function, a is the types are int *, sizeof (a) is 4, i.e., the number of bytes of a pointer; the third embodiment, the number of [] can easily fill in fact, no said array being given outside the range, type int *, sizeof (a) is 4, and generally do not use the third embodiment, the length of the array should be passed as a parameter. Type fifth embodiment is int [5] (assuming passed argument int array of length 5), sizeof (a) is 5 * 4 = 20.
All the above defined method, the parameter of the function modify the array, the array will change the argument.
Function call
When you call the array as a parameter to a function of only one way:
testfunc(a, size)
Two-dimensional array
Function definition
There are four ways a function definition:
One way:
void testfunc(int a[][3], int size0, int size1)
Second way:
void testfunc(int(*a)[3], int size0, int size1)
Three ways:
template<class T>
void testfunc(T a, int size0, int size1)
Four ways:
template<class T>
void testfunc(T& a, int size0, int size1)
The first three, in a function, a is the types are int (*) [3], sizeof (a) is 4, i.e., the number of bytes of a pointer; the fourth embodiment is the type int [2] [ 3] (assuming passed argument of length [2] [3] int array), sizeof (a) is 2x3x4 = 24.
Note that, when the number of columns must write parameter definition, do not write the number of rows.
Function call
When you call the array as a parameter to a function of only one way:
testfunc(a, size0, size1)