Array of pointers issue

Hi guys I'm having problem understand this block of code...Can someone help?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void myFunction (int* myPtr)
{
   int* x = myPtr + 1;
   x[2] = 10;
   myPtr = new int[5];
   for (int i = 0; i < 5; ++i)
      myPtr[i] = x[0] + i + 3;
}
int main()
{
   int* data = new int[6];
   data [0] = -2;
   for (int i = 1; i < 6; i++)
      data[i] = *(data +i - 1) + 2;
   *data = 10;
   int* temp = data;
   myFunction(data);
   return 0;
}


SO what I dont understand is that why there is an array namned "x"; the previous code had an array called data that pass into the function.. But will it pass on all the elements in data array so x will be pointing to the same array or x is just pointing to a single value in data? Hope someone can shed some light on this.. Thx!
Exactly
exactly pointing to the same data array? So what would int* x = myPtr + 1 mean?
translation :

I assign the address of the index 1 of the array myPtr to a pointer of type int called x.
So what would int* x = myPtr + 1 mean?

It means that x will be pointing to the second element of myPtr. So x[0] is the same as myPtr[1].

On calling myFunction with argument 'data', x[0] will be accessing data[1].

But it seems to me that overall, myFunction won't do almost anything. It just changes x[2] to 10, so that would change data[3] to 10.
Topic archived. No new replies allowed.