指针数组 :数组中存放的每个元素都是指针
数组指针 :指针指向的是一个数组
一维数组 char aa[5] = “1234”;
sizeof(aa) / sizeof(aa[0]) : 求数组的个数,包括结束符0 ,’’strlen(aa) : 求字符的总个数,不包括结束符 0,’’二维数组 char bb[4][5] = { “1234”,“1234” ,“1234” ,“1234” };
sizeof(bb) / sizeof(bb[0]) : 求二维数组的行数sizeof(bb[0]) / sizeof(bb[0][0]) :求二维数组每行的个数1,指针数组
//指针数组char* a = "abcdefg";char* b = "abcdefg";char* c = "abcdefg";char* d = "abcdefg";char* e = "abcdefg";//一共有5个指针,每个指针指向一个字符串char * pb[5] = { "abcdessfg" ,"abcdssssssssesfg" ,"abcdsssefg" ,"asbcsdefg" ,"abcdefg" };//因为存放的是指针,所以64位 指针大小为8 ,32位为 4//sizeof(pb)总数量/sizeof(pb[0])单个大小 int n = sizeof(pb) / sizeof(pb[0]);for (int i = 0; i < n; i++) {printf("%sn", pb[i]);}
2 数组指针
步长一定要一样数组指针指向一维数组与二维数组时的区别
//指向一维数组要加&char aa[5] = "1234";p = &aa;//数组指针指向二维数组char bb[4][5] = { "1234","1234" ,"1234" ,"1234" };p = bb;
//数组指针char(*p)[5] = NULL;//=============================================//指向一维数组要加&//p的【5】可看成p+1 的步长char aa[5] = "1234";p = &aa;//整行输出printf("paa = %sn", p);//按列输出for (int i = 0; i < sizeof(aa) / sizeof(aa[0]); i++) {printf("%c ", *( * (p + 0) + i));}//=============================================//=============================================char bb[4][5] = { "1234","1234" ,"1234" ,"1234" };p = bb;for (int i = 0; i < sizeof(bb) / sizeof(bb[0]); i++) {printf("%sn", *(p + i)); //每行的内容for (int j = 0; j < sizeof(bb[0]) / sizeof(bb[0][0]);j++) {printf("%c, ", *( * (p + i) + j)); //每行中的每个}printf("n");}