#include<stdio.h>
typedef char**?? ??? ??? ??? ?second_level_ptr; typedef second_level_ptr*?? ?three_level_ptr; typedef second_level_ptr**?? ?four_level_ptr;
// 常量指针 char * const p0 = "hello";
// 指针数组 == 二级指针 char *p1[3] = {p0, "hi", "hahaha"};?? ???// **p == *p[] ? ?p1的每个元素都是指针 char *p2[3] = {"zhao", "qian", "sun"}; char *p3[3] = {"li", "zhou", "wu"};?? ??? ??? ? char *p4[3] = {"zhen", "wang", "feng"};
//三级指针 char **p5[2] = { p1, p2 };?? ??? ??? ??? ??? ?// ***p = **p[] ? p5的每个元素都是指向二级指针 //char **p6[2] = { p3, p4 }; second_level_ptr p6[2] = { p3, p4 };
//四级指针 //char ***p7[2] = { p5, p6 };?? ??? ??? ??? ?// ****p = ***p[] p7的每个元素都是三级指针 three_level_ptr ?p7[2] = { p5, p6 };?? ?// ****p = ***p[] p7的每个元素都是三级指针
second_level_ptr?? ?p8 = p1;
three_level_ptr ? ? p9 = p5;
//char****?? ??? ??? ?p10 = p7; four_level_ptr ?? ??? ?p10 = p7;
int main(void) { ?? ?int i, j, k; ?? ? ?? ? ?? ?printf("----------------------------------------\n");
?? ?printf("二级指针\n"); ?? ?for (i=0; i < sizeof(p1)/sizeof(p1[0]); ++i) ?? ??? ?printf("*p1[%d] = %s\n", i, *(p1+i)); ?? ??? ? ?? ?printf("----------------------------------------\n");
?? ?printf("三级指针\n"); ?? ?for (i=0; i < 2; ++i) ?? ??? ?for (j=0; j < 3; ++j) ?? ??? ??? ?printf("*p5[%d][%d] = %s\n", i, j, *((p5[i])+j));
?? ?printf("----------------------------------------\n"); ?? ? ?? ?printf("四级指针,p7数组访问形式\n"); ?? ?for (i=0; i < 2; ++i)?? ??? ??? ?// p7有两个元素 ?? ??? ?for (j=0; j < 2; ++j)?? ??? ?// p5有两个元素 ?? ??? ??? ?for (k=0; k < 3; ++k)?? ?// p1有三个元素 ?? ??? ??? ??? ?printf("*p7[%d][%d][%d] = %s\n", i, j, k, *((p7[i][j])+k)); ?? ??? ??? ??? ? ?? ?printf("四级指针,p10数组访问形式\n"); ?? ?for (i=0; i < 2; ++i) ?? ??? ?for (j=0; j < 2; ++j) ?? ??? ??? ?for (k=0; k < 3; ++k) ?? ??? ??? ??? ?printf("*p10[%d][%d][%d] = %s\n", i, j, k, *((p10[i][j])+k)); ?? ?
?? ?printf("----------------------------------------\n");
?? ?return 0; }
|