案例代碼
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
//字元指針
char *pstr="good dog ww";
printf("字元指針指向的字元串内容:%s\n",pstr);
printf("字元指針本身的位址:%p\n",&pstr);
printf("字元指針指向的位址:%p\n",pstr);
printf("字元串常量的位址:%p\n","good dog ww");
printf("======================================\n");
//字元數組
char c[]="hello";
printf("字元數組内容:%s\n",c);
printf("字元數組位址:%p\n",c);
printf("字元數組位址:%p\n",&c);
printf("hello字元串常量的位址:%p\n","hello");
printf("..........................\n");
char *s="abcstring";
printf("s的内容:%s\n",s);
printf("s本身的位址:%p\n",&s);
printf("s指向的位址:%p\n",s);
printf("abcstring字元串常量的位址:%p\n","abcstring");
printf("...........................\n");
s="hello";
printf("s的内容:%s\n",s);
printf("s本身的位址:%p\n",&s);
printf("s指向的位址:%p\n",s);
printf("======================================\n");
//整型指針
int a=1;
printf("a的值:%d\n",a);
printf("a的位址:%p\n",&a);
printf("...........................\n");
int* b=&a;
printf("b的位址:%p\n",&b);
printf("b指向的位址:%p\n",b);
printf("b指向的内容:%d\n",*b);
getchar();
return 0;
}
輸出:
字元指針指向的字元串内容:good dog ww
字元指針本身的位址:0057FA7C
字元指針指向的位址:00EB5938
字元串常量的位址:00EB5938
======================================
字元數組内容:hello
字元數組位址:0057FA6C
字元數組位址:0057FA6C
hello字元串常量的位址:00EB5888
..........................
s的内容:abcstring
s本身的位址:0057FA60
s指向的位址:00EB5810
abcstring字元串常量的位址:00EB5810
...........................
s的内容:hello
s本身的位址:0057FA60
s指向的位址:00EB5888
======================================
a的值:1
a的位址:0057FA54
...........................
b的位址:0057FA48
b指向的位址:0057FA54
b指向的内容:1
*
/