Lets say we have an array
int a[4];
there was a neat trick using pointer arithmetics to find the last element. As far as i can recall it was using the address of 'a' and incrementing it so that it will go point immediately after the array and then going one position back.
The thought behind the incrementing was that that there was an implicit sizeof
being done. There was nowhere any explicit sizeof
.
Anyone have any idea how it was done?
Thanks a bunch!
I can suggest the following solution
#include <stdio.h>
int main( void )
{
int a[4] = { 0, 1, 2, 3, };
int *p = (int *)(&a + 1) - 1;
printf("*p = %d\n", *p);
return 0;
}
The program output is
*p = 3