char *a[]; 是一个指针数组,char (*a)[SIZE]; 是一个指向数组大小为SIZE的字符数组的指针。
以下代码进行测试:
//////////////////////////////////////////////////////////////////
//
// author: kangquan@scut2008
// blog: http://blog.youkuaiyun.com/kangquan2008
// descriptoion: test the difference betwenn * ch[] and (*ch)[];
//
//////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
char * ch[] = {
"Tuseday",
"Wednesday",
"Friday"
};
char array[3][SIZE] = {
"Tuseday",
"Wednesday",
"Friday"
};
char (*ch2)[SIZE] = array;
int main()
{
printf("sizeof ch: %d\n",sizeof(ch));// sizeof ch: 12
printf("sizeof array: %d\n",sizeof(array));// sizeof array: 60
printf("sizeof ch2: %d\n",sizeof(ch2));// sizeof ch2: 4
//ch++;//error: lvalue required as increment operand
printf("ch: %s\n",ch[0]);// ch: Tuesday
ch[0]++;
printf("ch: %s\n",ch[0]);// ch: uesday
printf("ch2: %s\n",ch2);// ch2: Tuesd