Say I have an array of a[5] , and base address is 3000 now , and I have to get the address of the last element a[4] and I have a pointer b , and I do
b=a+n-1 , so I have one confusion in this that first a+n would be executed like
a+n*sizeof(a) -1 ,now a+n*sizeof(a)= 3010 ,now when we do -1 from it , how does it evaluate to 3008 , the address of last element since contiguous memory cells are from address 3000 to 3008 so then how come 3010-1 evaluates to 3008 ,how does compiler come to know how much bytes it has to move backwards since 3010 is a random location .
b=a+n-1 , so I have one confusion in this that first a+n would be executed like
a+n*sizeof(a) -1 ,now a+n*sizeof(a)= 3010 ,now when we do -1 from it , how does it evaluate to 3008 , the address of last element since contiguous memory cells are from address 3000 to 3008 so then how come 3010-1 evaluates to 3008 ,how does compiler come to know how much bytes it has to move backwards since 3010 is a random location .
Comment