指针数组 :数组中存放的每个元素都是指针 数组指针 :指针指向的是一个数组
一维数组 char aa[5] = “1234”;
- sizeof(aa) / sizeof(aa[0]) : 求数组的个数,包括结束符0 ,’\0’
- strlen(aa) : 求字符的总个数,不包括结束符 0,’\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";
char * pb[5] = { "abcdessfg" ,"abcdssssssssesfg" ,"abcdsssefg" ,"asbcsdefg" ,"abcdefg" };
int n = sizeof(pb) / sizeof(pb[0]);
for (int i = 0; i < n; i++) {
printf("%s\n", pb[i]);
}
2 数组指针
步长一定要一样
数组指针指向一维数组与二维数组时的区别
char aa[5] = "1234";
p = &aa;
char bb[4][5] = { "1234","1234" ,"1234" ,"1234" };
p = bb;
char(*p)[5] = NULL;
char aa[5] = "1234";
p = &aa;
printf("paa = %s\n", 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("%s\n", *(p + i));
for (int j = 0; j < sizeof(bb[0]) / sizeof(bb[0][0]);j++) {
printf("%c, ", *( * (p + i) + j));
}
printf("\n");
}
|