可能重複:
C pointer to array/array of pointers disambiguation這個字符指針聲明是什麼意思?
是如何從char *p[4];
char (*p)[4];
不同?
可能重複:
C pointer to array/array of pointers disambiguation這個字符指針聲明是什麼意思?
是如何從char *p[4];
char (*p)[4];
不同?
char (*p)[4];
- 聲明數p作爲指針炭的陣列4。char *p[4];
- 將p聲明爲指向char的數組4。char (*p)[4];
:p
是指向一個char
陣列長度的4
char [4]
points to |
char [4] v
+------+ +------+------+------+------+
| p |------------>| | | | |
+------+ +------+------+------+------+
char char char char
p will point to a char [4] array. Array is not created.
p is intended to be assigned at address of a char [4]
char *p[4];
:p
是長度爲4的一個陣列,所述陣列的每個位置是一個指向char
+------+------+------+------+
p | | | | |
an array +------+------+------+------+
itself | | | |
v v v v
char* char* char* char*
p is an array and will be allocated in stack (if automatic)
但是,如何使用此「p作爲字符數組4的指針」 – 2012-04-29 14:45:21
,但是您需要! – 2012-04-29 14:45:34
是* p [0] =「你好」;或* p [0] =(char *)malloc(10);第一個聲明有效 – 2012-04-29 14:46:09