#include
int main(){
char i=0;
char *str1=&i;
char *str2=&i;
const char *str5="abc";
const char *str6="abc";
char *str7="abc";
char *str8="abc";
printf("i is %d\n",&i);
printf("str1 is %d\n",str1);
printf("str2 is %d\n",str2);
printf("str1 is %d\n",*str1);
printf("str2 is %d\n",*str2);
printf("str1 is %d\n",&str1);
printf("str2 is %d\n",&str2);
printf("%d\n",str1==str2);
printf("%d\n",str5==str6);
printf("%d\n",str7==str8);
}
执行后输出:
i is -1081608749
str1 is -1081608749
str2 is -1081608749
str1 is 0
str2 is 0
str1 is -1081608756
str2 is -1081608760
1
1
1
其结果表明,对指针的直接引用,就是该指针所保存的,以前倒是忽略了这一点。。。也更理解了《再再论指针》中所说的,地址和整形,字符型等一样,也是一种基本类型,指针只是存储这种数据类型的变量。比如说,对于int i=10,10是整数,而i是存储整数的变量,指针就好比这个i,地址就好比那个10。
阅读(1758) | 评论(0) | 转发(0) |