c语言多维指针笔记


#include

int main(void)
{

int a[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9 ,10, 11, 12};
char s[3][10] = {"hello", "world", "friend!"};

printf("%u\n", (unsigned int)a); // int (*)[4]
printf("%u\n", (unsigned int)(a+1));
printf("%u\n", (unsigned int)(a+2));
printf("%u\n", (unsigned)*a); // 对int (*)[4]的指针取内容,得到
printf("%u\n", (unsigned)*(a+1)); // 一个int型数组, *a表示一个int型数组,
printf("%u\n", (unsigned)*(a+2)); // 所以是int*类型
printf("%d\n", *(*a+1));
printf("%d\n", *(*(a+1)+1)); // *(a+1)是一个int*类型,所以*(a+1)+1
【c语言多维指针笔记】printf("%d\n", *(*(a+2)+1)); // 指向下一个数组元素,*(*(a+1)+1) 取出该元素
printf("%s\n", s); // char (*)[10]
printf("%s\n", s+1);
printf("%s\n", s+2);
printf("%s\n", *s);
printf("%s\n", *(s+1));
printf("%s\n", *(s+2));
printf("%s\n", *s+1);
printf("%s\n", *(s+1)+1);
return 0;
}

    推荐阅读