编写test.c
#include <stdio.h>
#include <stdlib.h>
typedef struct STUDENT_S
{
char name[12];
int grade;
int score;
} __attribute__ ((__packed__))STUDENT_T;
int main()
{
STUDENT_T *p;
STUDENT_T a[] ={{"jacky",3,88},{"tom",3,90}};
p = a;
printf("sizeof a is %u\n", sizeof(a));
printf("sizeof a[0] is %u\n", sizeof(a[0]));
printf("items of a is %u\n", sizeof(a)/sizeof(a[0]));
printf("addr of a is %p\n", a);
printf("addr of &a is %p\n", &a); // a的值与&a的值,应该相等
printf("addr of a+1 is %p\n", a+1); // a+1的值,应该比a大20
printf("addr of &a+1 is %p\n", &a+1); // &a+1的值,应该比我大40
printf("addr of ++p is %p\n", ++p);
}
gcc -o test test.c
执行test,结果如下:
sizeof a is 40
sizeof a[0] is 20
items of a is 2
addr of a is 0x7fffdf189f80
addr of &a is 0x7fffdf189f80
addr of a+1 is 0x7fffdf189f94
addr of &a+1 is 0x7fffdf189fa8
addr of ++p is 0x7fffdf189f94