Search code examples
cpointerspointer-to-array

While dereferencing pointer to an array I am getting same address as that of pointer to an array


#include<stdio.h>

int main(void)
{
   int arr[5]={1,2,3,4,5};
   int (*ptr)[5]=&arr;

   printf("ptr=%p\n",ptr);    i am not getting the diff btw both statements
   printf("*ptr=%p\n",*ptr);

   return 0;
}

output:- 
ptr=0xbf8f8178
*ptr=0xbf8f8178

I know dereferencing the pointer to an array we get the array name and array name denotes the base address then what's the diff between both statements


Solution

  • the first pointer in printf is pointer to pointer

    the second pointer in printf is pointing to first element pointed by the first pointer

    but the types of two pointers are different

    enter image description here

    see this image

    source:https://www.eskimo.com/~scs/cclass/int/sx9b.html