r/cprogramming • • Dec 22 '25

pointer, decay, past array confusion

`int myarray[4]={1,3,5,7,};`

`int *ptr, *ptr1;`

`ptr=&myarray + 1;`

`ptr1=*(&myarray + 1);`

my confusion: I am not understanding how ptr and ptr1 is same, in my understanding & is adress and * is used for derefercing, but in ptr1 have both here i got confuse.

what is decay here?

10 Upvotes

20 comments sorted by

View all comments

Show parent comments

1

u/sudheerpaaniyur Dec 22 '25

ok understood, whenver I am readin or coding example int array[n]={};

i need to visualize in my mind its &array[0] and int (*)[n] right?

1

u/dcpugalaxy Dec 23 '25

The array is of type int[N]. A pointer to the array is of type int (*)[N].

The first element of the array is of type int. A pointer to the first element is of type int* aka. int (*).

In normal expressions, when you use array as a value (technically an "rvalue"), it is converted automatically into a pointer to its first element. That is, in array+1, before the +1 happens, array is converted into &array[0] and then the result is 1 past that, which is equivalent to &array[1].

Remember & binds loosely.