資源描述:
《指針指針數(shù)組、多級指針、動態(tài)指針》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、1數(shù)組指針——以此類推一維數(shù)組名是“列指針類型”----“元素指針類型”指針變量的定義:int*p;二維數(shù)組名是“行指針類型”指針變量的定義:int(*p)[4];三維數(shù)組名是“頁指針類型”指針變量的定義:int(*p)[3][4];四維數(shù)組名是“塊指針類型”指針變量的定義:int(*p)[3][4][5];圓括號是必須的2問題的提出變量是用于存放單個數(shù)據(jù)的數(shù)組是用于存放“同類型”的多個數(shù)據(jù)的方便循環(huán)控制結(jié)構(gòu)的編程指針變量是用于存放單個地址號的“同類型”的多個地址號是否能夠集中存儲在一起構(gòu)成“指針數(shù)組”呢?3元素均為指針類型數(shù)據(jù)的數(shù)組,稱為指針數(shù)組定義形式
2、為:類型關(guān)鍵字*數(shù)組名[數(shù)組長度];例如char*pStr[5];pStr[5]*char四、指針數(shù)組注意沒有圓括號4例:二維字符數(shù)組voidmain(){inti;charstr[][10]={"Pascal","Basic","Fortran","Java","VisualC"};for(i=0;i<5;i++){printf("%s",str[i]);}}strstr[0]Pascalstr[1]str[2]str[3]BasicFortranJava二維數(shù)組VisualCstr[4]5例:字符指針數(shù)組voidmain(){inti;char*p
3、tr[]={"Pascal","Basic","Fortran","Java","VisualC"};for(i=0;i<5;i++){printf("%s",ptr[i]);}}ptr[0]Pascalptr[1]ptr[2]ptr[3]BasicFortranJavaptr指針數(shù)組字符串ptrVisualCptr[4]6例:字符串按字典順序排序—二維數(shù)組編程charstr[N][10]={"Pascal","Basic","Fortran","Java","VisualC"};for(i=0;i4、){if(strcmp(str[j],str[i])<0){strcpy(temp,str[i]);strcpy(str[i],str[j]);strcpy(str[j],temp);}}}strstrstrstrstrstrstrstrstrstr7例:字符串按字典順序排序—指針數(shù)組編程char*ptr[N]={"Pascal","Basic","Fortran","Java","VisualC"};for(i=0;i5、ptr[i]=ptr[j];ptr[j]=temp;}}}指針數(shù)組ptr字符串排序前Pascal