2012-04-29 113 views

回答

8

http://cdecl.org/

  1. char (*p)[4]; - 聲明數p作爲指針炭的陣列4。
  2. char *p[4]; - 將p聲明爲指向char的數組4。
+0

但是,如何使用此「p作爲字符數組4的指針」 – 2012-04-29 14:45:21

+2

,但是您需要! – 2012-04-29 14:45:34

+0

是* p [0] =「你好」;或* p [0] =(char *)malloc(10);第一個聲明有效 – 2012-04-29 14:46:09

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) 
+0

謝謝!得到它了!! – 2012-04-29 15:01:01

+0

指針,圖片總是幫助:) – phoxis 2012-04-29 15:09:05

+2

在char(* p)[4]的情況下'注意聲明不創建數組,只有指向一個的指針是很重要的。 – kittemon 2012-04-29 15:13:38