Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is char ** in C? [duplicate]

Tags:

c

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! :)

like image 338
mccormickt12 Avatar asked Nov 13 '12 00:11

mccormickt12


People also ask

What does char * p mean in C?

In C programming language, *p represents the value stored in a pointer and p represents the address of the value, is referred as a pointer. const char* and char const* says that the pointer can point to a constant char and value of char pointed by this pointer cannot be changed.

Is a char * the same as char in C?

The fundamental difference is that in one char* you are assigning it to a pointer, which is a variable. In char[] you are assigning it to an array which is not a variable.

How do you duplicate a string?

The C library function to copy a string is strcpy(), which (I'm guessing) stands for string copy. Here's the format: char * strcpy(char * dst, const char * src); The dst is the destination, src is the source or original string.

How do you copy a character in C?

Copying one string to another - strcpystrcpy can be used to copy one string to another. Remember that C strings are character arrays. You must pass character array, or pointer to character array to this function where string will be copied. The destination character array is the first parameter to strcpy .


3 Answers

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.

like image 150
tdk001 Avatar answered Oct 06 '22 01:10

tdk001


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.

like image 25
kevintodisco Avatar answered Oct 06 '22 01:10

kevintodisco


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.

like image 22
iceout Avatar answered Oct 06 '22 02:10

iceout