#include <stdio.h>
int main()
{
char a = 'F';
int b =123;
char *pa = &a;
int *pb = &b;
printf("a = %c\n", *pa);
printf("b = %d\n", *pb);
*pa = 'C';
*pb += 1;
printf("now, a = %c\n", *pa);
printf("now, b = %d\n", *pb);
printf("The addr of a is %p\n", pa);
printf("The addr of b is %p\n", pb);
printf("The length of pa is %d\n", sizeof(pa));
printf("The length of pb is %d\n", sizeof(pb));
return 0;
}
输出为:
a = F
b = 123
now, a = C
now, b = 124
The addr of a is 0060FF07
The addr of b is 0060FF00
The length of pa is 4
The length of pb is 4
既然指针所占内存空间为4个字节,为什么地址相差8个字节呢?
网友评论