Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
Akash_Kumar You are taking an address of an array and assuming it's the same thing as the address of its first element. It's not. The types are different, and the pointer arithmetic is different too.Pointer arithmetic is done in units of "size of pointee". Since &a is a pointer to an array of 3 int - an int (*)[3], adding 1 to it moves it 3*sizeof(int) bytes. That makes ptr points to the element next to the last element of the array and hence *(ptr-1) generates last element.
16th May 2020, 12:41 AM
Arsenic
Arsenic - avatar
+ 2
Same question has been asked and answered before.👇 https://www.sololearn.com/discuss/1571838/?ref=app
15th May 2020, 3:20 PM
Arsenic
Arsenic - avatar