重複の可能性:
配列へのCポインター/ポインターの配列の曖昧性解消
とどうchar (*p)[4];
違うのchar *p[4];
?
char (*p)[4];
--pをcharの配列4へのポインタとして宣言します。char *p[4];
--pをcharへのポインタの配列4として宣言します。char (*p)[4];
:は長さ4p
の配列へのポインタです。char
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)