code example:
Int _tmain (int argc, _tchar* argv[]) {#pragma pack (1) typedef struct{ int a; char x; int y; char z[6]; }aaa; printf ("%d\n", sizeof (AAA)); aaa a = {1, ' A ', 2, ' Bcdef '}; aaa* pa = &a; int* test1 = (int *) (void *) pa; char* test2 = (char *) (void *) (test1+1); int* test3 = (int *) (void *) (test2+1); char* test4 = (char *) (void *) (test3+1); printf ("%d ", *test1); printf ("%c ", *test2); printf ("%d ", * TEST3); printf ("%s", test4); return 0; #pragma Pack ()} compiler: visual studio2010 Note: 1, the pointer performs the addition and subtraction, is to multiply the decrement value by the size of the pointer type as the number of bits shifted, and therefore need to be strongly converted to the type of the required pointer type as the operand. 2, the structure of the body can not be automatically aligned with the character, you must use the #pragma pack compiler guidance will be aligned with the minimum word subscript character to 1, otherwise the offset value operation can not reach the specified position
C + + struct body value by pointer shift