0

Is the address of the first element of the array and the address of the array name pointer is same in C programming?

And what if we create a pointer(p) to the first element(a[0]) of the array(a[5]) then the address of the pointer(p) , first element(a[0]) and the default pointer(a) will be same? `

As my conclusion and research the address of the first element(a[0]) and the address of the array name pointer(a) is same but the pointer(p) which I have created holds the address value of the first element of the array(a[5]) but its address is different.

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • 1
    What exactly do you mean by _"the array name pointer"_? Can you show it in code? – Ted Lyngmo Jul 20 '23 at 14:55
  • 1
    Please present actual code demonstrating what pointer values you are asking about. Also, please do some searching around for yourself, because at least part of the question I *think* you are asking is already answered many times over here. – John Bollinger Jul 20 '23 at 14:56
  • 1
    Related: [What is array to pointer decay?](https://stackoverflow.com/q/1461432/12149471) – Andreas Wenzel Jul 20 '23 at 14:56
  • @TedLyngmo: My guess is that OP is referring to the decayed pointer that you get when you use the array's name. – Andreas Wenzel Jul 20 '23 at 14:57
  • 1
    Not sure what you mean by “default pointer” but given: `char buf[10]; char *p = buf; char *q = &buf[0];` `p` and `q` will be equal, both point to the first character in `buf`. A code example showing your “research” would be helpful. – Paul Lynch Jul 20 '23 at 14:59
  • @AndreasWenzel That's possible. I hope OP will clarify it. – Ted Lyngmo Jul 20 '23 at 15:00
  • Given `SomeType array[10];`, the value of `&array` is of type `SomeType (*)[10]` and the type of `&array[0]` is `SomeType *` — these are (manifestly) not the same type. However, the byte patterns of the two addresses are the same: `printf("%p %p\n", (void *)&array, (void *)&array[0]);` will print the same value. – Jonathan Leffler Jul 20 '23 at 15:03
  • @Mohd Saq, "Is the address of the first element of the array and the address of the array name pointer is same in C programming?" --> They have different types. The 2 pointers have an _equivalent_ value. They compare the same, yet may have a different bit pattern. – chux - Reinstate Monica Jul 20 '23 at 15:31

0 Answers0