1

According to this response pointers to pointers

char[] = char *p
char[][] = char **p

But, when I initialize an array of strings with the next two forms

char **p = {"Hello", "World"};
char p[][] = {"Hello", "World"};

The compiler shows me some Error.

[Error] array type has incomplete element type

But with

char *matriz[] = {"Hello", "World"};

There is no warning. I'm new in C language, and I'm very confused.

11
  • C, sorry I will remove the C++ tag Commented Aug 29, 2015 at 14:46
  • 2
    You cannot have dynamic-sized arrays in C, and that's not a warning, it is an ERROR Commented Aug 29, 2015 at 14:47
  • 1
    The answer in the link does not state what you are supposedly quoting!!! Commented Aug 29, 2015 at 14:51
  • What you quote ,states that arrays and pointers are same ? Is that what you meant? Commented Aug 29, 2015 at 14:53
  • 3
    Any document that equates char[][] with char ** is not going to be dreadfully helpful; the two are quite different. In fact, char[] is not the same as char * either, but when you use those notations in the parameter list for a function, they are equivalent (that is: void something(char data[]) and void something(char *data) are equivalent in this one important context). However, void otherthing(char data[][10]) and void otherthing(char **data) are not equivalent at all. Commented Aug 29, 2015 at 16:11

1 Answer 1

6

No an array of array is not the same as a double pointer. You really should read that up, there are a lot of FAQ and answers around.

Then the error that you receive is for the doubly empty [][]. In C, when you declare an array with [] the compiler tries to compute the size of the array from the initializer. This only works for one []. For the second you have to give a length. Something like

char p[][7] = {"Hello", "World"};

should work. For your first form

char **p

this declares a pointer to pointer, so in particular a pointer. Pointers can't be initialized with two items, they need just one, and that should itself be of the correct pointer type or convert to it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.