#include <stdio.h>
typedef struct
{
int end;
struct
{
short a;
int b;
};
int d;
}test1_t;
int main()
{
printf(“sizeof(test1_t) = %ld\n”, sizeof(test1_t));
test1_t a1;
char* b1 = &a1;
printf(“b1 = %d\n”, b1);
b1+=1;
printf(“b1 = %d\n”, b1);
b1 = ((test1_t*)b1) +1;
printf(“b1+=1==>b1 = %d\n”, b1);
char *b2 = NULL;
b2 = b1+1;
printf(“b2 = %d\n”, b2);
return 0;
}
上述是测试例子
测试结果如下:
sizeof(test1_t) = 16
b1 = 1500815200
b1 = 1500815201
b1+=1==>b1 = 1500815217
b2 = 1500815218
结论:
在强转过后,指针b1仍然是一个指向char的指针。