C ++ array reference, array reference
C ++ array reference 1. array reference
C ++ array reference:
Alias
This is more convenient than the pointer transfer address.
(& A) [10] In the parameter can be considered as the alias of array a. You must specify the array size. If there is no subsequent array size, day knows whether it is a variable or an array.
Comparison between common values and reference values:
Ordinary values in the array: a --> a [10] (or a [])
Array reference: a --> (& a) [10]
Common variable values: a -->
Variable reference: a --> (&)
It's easy to understand.
Ii. code example
1/* 2 C ++ array reference: 3 the alias 4 is more convenient than the transfer address (&) [10] can be regarded as the alias of array a. You must specify the array size. If there is no subsequent array size, the day will know whether it is a variable or array 6. The normal pass value is compared with the reference pass value: 7. Common array values: a --> a [10] (or a []) 8. array reference values: a --> (&) [10] 9. Variable common pass value: a --> a10 variable reference pass value: a --> (& a) 11 analogy, good understanding of 12 13 test results: 14 0 0 0 0 0 0 0 0 0 0 15 0 1 1 2 3 4 5 6 7 8 9 16 */17 18 # include <iostream> 19 using namespace std; 20 void test (int a [10]); // a normal value of the array, used to print the value of array a 21 void readData (int (& a) [10]); // array reference pass value: assign a value to array a to array 0-9 22 void printData (int (& a) [10]); // array reference pass value: used to print the value of array a 23 void test (int a [10]) {// The ordinary pass value of array, used to print the value of array a 24 for (int I = 0; I <10; I ++) 25 {26 printf ("% d", a [I]); 27} 28 printf ("\ n "); 29} 30 void readData (int (& a) [10]) {// array reference value: assign a value to array a to array 0-9 31 for (int I = 0; I <10; I ++) 32 {33 a [I] = I; 34} 35} 36 void printData (int (& a) [10]) {// array reference pass value: used to print the value of array a 37 for (int I = 0; I <10; I ++) 38 {39 printf ("% d ", a [I]); 40} 41} 42 int main () {43 int a [10] = {0 }; // The initial value of each element in array a is 044 test (a); // a normal value of the array, used to print the value of array a 45 readData (); // array reference pass value: assign a value to array a to 0-9 46 printData (a); // array reference pass value: used to print the value of array a 47 48 return 0; 49}
Iii. Test Results
Test results:
0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9