1.CodeAs follows:
# Include <stdio. h> Int Main (){ Int A [ 5 ] = { 1 , 2 , 3 , 4 , 5 }; Int * Ptr1 = ( Int *) (& A + 1 ); Int * Ptr2 = ( Int *)(( Int ) A + 1 ); Int * Ptr3 = ( Int *) (A + 1 ); Printf ( " % X, % x, % x \ n " , Ptr1 [- 1 ], * Ptr2 ,* Ptr3 ); Return 0 ;}
The output is "5, 2000000, 2"
What will be output if printf ("% x \ n", * ptr1?
2. Post the code in memory
What is the value of P + 1 for a pointer? This 1 should be sizeof (* P), that is, the size of the structure pointed to by P, so & A + 1 = & A + sizeof (A) = 0x28ff04, A + 1 = a + sizeof (* A) = 0x28fef4, (INT) A + 1 = a + 1 = 0x28fef1;
Ptr1 [-1] = * (ptr1-1) = * (ptr1-sizeof (INT) = * (0x28ff00) = 5;
* Ptr2 = * (0x28fef1) = (memory small-end storage) 00 00 00 02 = 0x2000000;
* Ptr3 = * (0x28fef4) = 2;
* Ptr1 = * (0x28ff04) = 0x28ff04; this is not a coincidence, because ptr1 is defined after array A and followed by array a in memory.