-3

Let me give an example to understand my question :

void fct1()
{
 int T[20];
 int* p=T;//the goal is to modify this pointer (p)
 fct2(&p);
}
void fct2(int** p)
{
  (*p)++;//this will increment the value of the original p in the fct1
}

What i want is to avoid pointers and do it only with references , it's possible ?

Taoufik J
  • 700
  • 1
  • 9
  • 26

2 Answers2

1

Yes, it can be done using references.

void fct2(int* &p) {
    p++;
}
HelloWorld123456789
  • 5,299
  • 3
  • 23
  • 33
0

I would recommend using the iterators provided by std::array if possible:

void fct1()
{
    std::array<int, 20> l;
    auto it = l.begin();
    fct2(it);
}

template<class I>
void fct2(I& it)
{
    ++it;
}
David G
  • 94,763
  • 41
  • 167
  • 253