array and array pointer same thing?

From my understanding, when you declare something like char str[] = 'abc', it by default becomes a pointer to the first address of the array, so there is no need to specify the * syntax. However, sometimes I see something like in the below code, where it uses both [] and *. What exactly is going on here? I know that the [] operator has higher precedence than the * operator. So first thing it does I assume is point to the first address in the array, and then the * points again to the first address?

1
2
3
4
5
6
7
8
9
10
11
12
13
  char *leftstr[] =
  {
    "",

    "a",

    "antidisestablishmentarianism",

    "beautifications",

    "characteristically"

  };
No. That's defining an array of pointers. The char * is the type of the array.

You can see that from the way it's initialised - each element of the array is, itself, a C-string.
Your declaration is equivalent to this one below.

1
2
3
4
5
6
7
8
9
10
11
12
char test[5][29] =
{
    "",

    "a",

    "antidisestablishmentarianism",

    "beautifications",

    "characteristically"
};


All your compiler does is set the array's size all by himself.
Last edited on
Your declaration is equivalent to this one below.

No, it isn't. The code in the OP defines an array of pointers to char. Your code is a two dimensional array of char.

http://ideone.com/vLu0gn

Topic archived. No new replies allowed.