If we consider int to be 4 bytes here and assuming Little Endian mechanism to store the bytes of the variable ( which is followed in almost all of the architectures ). , as 'i' is declared as int and assigned the value of 511 , so the binary equivalent will be stored as :
00000000 00000000 00000001 11111111
Now the lowermost byte is "11111111" , hence it is stored at lowermost address , say at address 1000..Hence contents of addresses 1000 , 1001 , 1002 and 1003 in that order following Little Endian Notation :
11111111 00000001 00000000 00000000
Now at present , &i contains address of 'i' as an int.
To access the data bytewise (as we know 1 char = 1 byte) , we typecast the integer pointer to char pointer first and then dereference it which is done by step : char * ptr = (char*) &i ;
Hence now on dereferencing we will get the data bytewise..
Hence now on dereferencing data at location 1000 , we will get 1 B data instead of 4 B..
Hence *ptr will give us value = decimal equivalent of 11111111 = 255
But we know that data is stored is stored in 2's complement form..
Hence we need to take 2's complement of the bit pattern to get true magnitude .
Hence -1 should be the correct answer..