0

I have a question with double pointer to pointer array. I couldn't understand why is *double_pointer value same with *pointer_array value. I thought maybe there's something with this line, 'int **pptr = ptr'.
why isn't it 'int **pptr = &ptr' ? Please help me..

#include <stdio.h>

int main(){


  // doulble pointer with array.
  int arr[4] = {1,2,3,4};
  int *pt = arr;
  int **ppt = &pt;
  printf("%p, %d\n", *ppt, *pt);
  // The result is different. *ppt != *pt

  // double pointer with pointer array.
  int ptr1[4] = {1,2,3,4};
  int ptr2[4] = {5,6,7,8};
  int ptr3[4] = {9,10,11,12};
  int * ptr[3] = {ptr1, ptr2, ptr3};
  int ** pptr = ptr;
  // Why is it ptr? I thought it should be &ptr.

  printf("%p, %p\n", *pptr, *ptr); 
  // The result is same. *pptr = *ptr
  // Why *pptr is the address of ptr1? It thought should be the address of ptr.


  return 0;

}
Pepper
  • 13
  • 4
  • 2
    Do you know about array to pointer decay? – tadman Apr 26 '21 at 03:17
  • @tadman you mean dereferencing and not decay? – John Alexiou Apr 26 '21 at 03:21
  • 3
    Nope, [decay](https://stackoverflow.com/questions/1461432/what-is-array-to-pointer-decay). – Nate Eldredge Apr 26 '21 at 03:24
  • @tadman This situation is called array to pointer decay? I'll search it. Thank you. – Pepper Apr 26 '21 at 03:25
  • to be clear, you are asking why assigning `ptr` to a variable results in that variable's value being `ptr` , and not being `&ptr` ? That is how assignment works – M.M Apr 26 '21 at 03:32
  • @M.M Oh.. I thought this line (int ** pptr = ptr) is resemble with this line (int **ppt = &pt)... But it is actually resemble with (int *pt = arr) this line? I should think over this more. Thank you. – Pepper Apr 26 '21 at 03:40

0 Answers0