0

I am learning C++. I thought i understood pointers.

But this below, is something i can't wrap my mind around. Not to mention i don't know even if it's right way to do it.

int *ip[5];
int arr[5] = {};
**ip = *arr;

This compiles. But ip[3] is not 0, as arr[3] is. I want to know two things: what is happening, and how can i do what i wanted.. make ip equal arr.

Array is already like a pointer. So int *p; int arr[3]={}; p=arr; p[1];//== 0.. Then int *p[3]; int arr[3]; //

Muhammad Umer
  • 17,263
  • 19
  • 97
  • 168
  • 2
    `ip` will never be "equal [to]" `arr`; one is an array of integers, and the other is an array of five pointers. What are you trying to achieve and why are you doing it this way? – Lightness Races in Orbit Nov 01 '14 at 19:46
  • 1
    _"Array is already like a pointer."_ No – Lightness Races in Orbit Nov 01 '14 at 19:47
  • This is far from duplicate of that question..answers there just give general overview of arrays. While i am asking how to make array of pointers equal to array that has been initialized to zero. The shortest way to do it. Answers there don't explain double *, and don't even talk about my question. Yes i understand array is not pointers, but what i meant to say is that accessing array is like accessing pointer values. – Muhammad Umer Nov 02 '14 at 01:55
  • Each entry of ip can hold the address of an integer. Each entry of arr holds an integer - in this case, initialized to 0. What you _can_ do is to make each entry of `ip` hold the address of the element in `arr` that has the sane index. Do this with a loop for each of the 5 values of `n`. `ip[n] = &arr[n];` – enhzflep Nov 02 '14 at 03:39

0 Answers0