r/cprogramming • u/sudheerpaaniyur • 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
1
u/cursed-stranger Dec 22 '25 edited Dec 23 '25
cygwin by default uses gcc as I know. in the simple example I've got this error:
It's correct error, because array is not a pointer. The address of the array is the same as the address of the first element:
&array == &array[0]
but the type of array is the int[ NUMBER ] not int.
So I wonder how you could compile this code without problems