这是将向量传递给函数的两种方式。我想问:这两种情况都一样吗?就像声明为arr[90]
的数组一样
通过&arr
和arr
?两者都传递时,它们表示数组的基址相同。
案例1:
int binarySearch(int first, int last, int search4, vector<int>& random);
vector<int> random(100);
// ...
found = binarySearch(first, last, search4, random);
案例2:
int binarySearch(int first, int last, int search4, vector<int>* random);
vector<int> random(100);
// ...
found = binarySearch(first, last, search4, &random);