pointer & two-dimentional arrays

P352/1438
int data[3][4] = {{1,2,3,4}, {9,8,7,6}, {2,4,6,8}};
int total = sum(data, 3);

int sum(int (*ar2)[4], int size);行指针(数组指针)
int sum(int ar2[][4], int size);

The simplest way is to use brackets twice, as in ar2[r][c]. But it is possible, if

ungainly, to use the * operator twice:
ar2[r][c] == *(*(ar2 + r) + c)  // same thing
To   u n d e r s t a n d   t h i s , you can work out the meaning of the subexpressions from the
inside out:
ar2               // pointer to first row of an array of 4 int
ar2 + r          // pointer to row r (an array of 4 int)
*(ar2 + r)       // row r (an array of 4 int, hence the name of an array,
                     // thus a pointer to the first int in the row, i.e., ar2[r]
*(ar2 +r) + c    // pointer int number c in row r, i.e., ar2[r] + c

*(*(ar2 + r) + c)  // value of int number c in row r, i.e. ar2[r][c]

P555/1438

const Stock & topval(const Stock & s) const;
This function accesses one object implicitly and one object explicitly,and it returns a
reference to one of those two objects.The  constin parentheses states that the function
won’t modify the explicitly accessed object,and the constthat follows the parentheses
states that the function won’t modify the implicitly accessed object. Because the function
returns a reference to one of the two  constobjects, the return type also has to be a  const
reference

你可能感兴趣的:(pointer & two-dimentional arrays)