31

Possible Duplicate:
What is double star?

I am fairly new to C, and have come across this statement

typedef char **TreeType

I have a pretty good idea of what typedef does, but I have never seen char** before. I know that char* is a char array or similiar to a string. Im not sure if char** is a 2d char array or if it is the pointer to a character array. I have looked around but cannot find what it is. If you could please explain what a char** is or point me in the right direction it would be very much appreciated.

Thanks! :)

Community
  • 1
  • 1
mccormickt12
  • 575
  • 1
  • 7
  • 14

3 Answers3

35

Technically, the char* is not an array, but a pointer to a char.

Similarly, char** is a pointer to a char*. Making it a pointer to a pointer to a char.

C and C++ both define arrays behind-the-scenes as pointer types, so yes, this structure, in all likelihood, is array of arrays of chars, or an array of strings.

tdk001
  • 1,014
  • 1
  • 9
  • 16
7

It is a pointer to a pointer, so yes, in a way it's a 2D character array. In the same way that a char* could indicate an array of chars, a char** could indicate that it points to and array of char*s.

kevintodisco
  • 5,061
  • 1
  • 22
  • 28
4

well, char * means a pointer point to char, it is different from char array.

char amessage[] = "this is an array";  /* define an array*/
char *pmessage = "this is a pointer"; /* define a pointer*/

And, char ** means a pointer point to a char pointer.

You can look some books about details about pointer and array.

iceout
  • 438
  • 3
  • 7
  • 3
    In your example, `amessage` is still a pointer, which points to the beginning of your statically-sized `char` array. The syntax `*` is often indicative of an array, despite `*` being, by itself, a pointer. – kevintodisco Nov 13 '12 at 00:38
  • @ktodisco This example is from K&R. `amessage` is an array, just big enough to hold the sequence of characters and `\0` that initializes it. – iceout Nov 13 '12 at 01:05
  • 1
    If you look at the disassembly for those two statements, you will find they are both, at their core, pointers. I'll also refer you to the second post [here](http://www.cplusplus.com/forum/articles/10/). – kevintodisco Nov 13 '12 at 01:35