I need to use pointer with address of
Here, & does not mean "address of"; it means the type "reference to".
It's clearer if you write it not like this:
vector<int>* &primes
but like this:
vector<int>*& primes
Though the choice of whitespace is artificial, that better documents that this & is "part of the type".
Have some types:
std::vector<T> = A vector of Ts std::vector<T>& = A reference to a vector of Ts std::vector<T>* = A pointer to a vector of Ts std::vector<T>*& = A reference to a pointer to a vector of Ts std::vector<T>*** = A pointer to a pointer to a pointer to a vector of Ts std::vector<T>**& = A reference to a pointer to a pointer to a vector of Ts
…and so forth.
As for why you need a vector<int>*& for printPrimes to do its job, we could not tell you without actually being able to see it. I will say that it seems unlikely it needs a pointer at all, and that if it wants to modify that pointer it's going to cause problems with the new and delete in the calling scope.
In fact, all that dynamic allocation is completely pointless and only complicates things.
The following was likely intended instead:
void printPrimes(long long l, long long r, vector<int>& primes) { // some code } vector<int> sieve() { vector<int> prime; return prime; } int main() { vector<int> primes = sieve(); printPrimes(l, r, primes); }
&means reference, not address of.vector<int>* &primesdeclaresprimesto be a reference to a pointer to avectorofintelements. You might need it if you want to change where the pointer is pointing. It's unlikely you need to do that though, so stop using pointers at all.