标签:int 指针变量 include char s char print 引用 2-2 \n
2-1.c数组指针的定义:
#include <stdio.h> int main() { char str[]="China Beijing Fujian"; //定义数组str并进行初始化 char *pstr; //定义指针变量pstr pstr=&str[6]; //初始化pstr,并使指针变量pstr指向数组str printf("str:%s,str"); printf("pstr指向str[6]:%c\n,*pstr"); return 0; }
结果:
[root@centOS code]# gcc 2-1.c -o 2-1 [root@centOS code]# ./2-1 str:China Beijing Fujian pstr指向str[6]:B
2-2.c数组指针的引用
#include <stdio.h> int main(void) { char str[]="China Beijing Fujian"; char *pstr; printf("str:%s\n",str); pstr=str; printf("pstr->str:%s\n",pstr); printf("&str=%p\n",&str); printf("pstr=%p\n",pstr); printf("&str[0]",&str[0]); return 0; }
结果:
[root@centOS code]# gcc 2-2.c -o 2-2 [root@centOS code]# ./2-2 str:China Beijing Fujian pstr->str:China Beijing Fujian &str=0x7fffd12e1c80 pstr=0x7fffd12e1c80
(未完待续.........)
标签:int 指针变量 include char s char print 引用 2-2 \n
原文地址:https://www.cnblogs.com/happying30/p/9374461.html