理解的关键在于:
1. []的优先级高于*,(*p)[]理解为指向一个数组,*(p[])存放指针的数组
2. char (*p)[SIZE]:指向一维数组的指针,一维数组只能有SIZE个元素
char *p[SIZE]:指针数组,数组有SIZE个元素
代码测试:
- #include <stdio.h>
- #define TESTSIZE 20
- int main(void)
- {
- char szTest[][TESTSIZE] = {"hello", "world"};
- char (*p)[TESTSIZE];
- p = szTest;
- for(int i = 0; i < sizeof(szTEST)/TESTSIZE; i++)
- {
- printf("%s", p + i);
- }
- }
- #include <stdio.h>
- #define STRSIZE 20
- int main(void)
- {
- char *p[] = {"hello", "world!"}; //p[],数组
- for(int i = 0; i < 2; i++)
- printf("%s ", p[i]);
- return 0;
- }