Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers, namely char **args;

Status
Not open for further replies.

krissi

Technical User
Aug 16, 2001
3
AU
Hi all,

I am looking at the source code of a program, and I am a bit confused over a particular part of it.

What does char **args; mean ?
I understand the concept of pointers, but I'm not to sure on the double asterisks!!!

If someone can tell me it'd be much appreciated!
Thanks!!
Krissi

-----------
FYI - code

int main(int argc, char *argv[])
{
char **args;
char input[MAX_STR_LENGTH];
int i;

//Rest of program...
}
 
If a program executed with some arguments, for example :
my-program a b c

the main function receives its arguments to 'argv' like
this

char* arg[] = { "my-program", "a", "b", "c", NULL };

and 'arg' is char**.
Hee S. Chung
heesc@netian.com
 
The 2 second definition is
it is a pointer to a pointer. In this case it is a character pointer pointing to a character pointer which in essence can be thought of as an array.

Ex:

char str[]= "Example";
char* pstr = str;

char str2[2][2];
char** pstr2 = str2;

char str3[] = "hello";
str2[0] = str;
str2[1] = str3;

hope that helps a bit.

Matt
 
Zyrenthian, you made some mistakes.

1. char str2[2][2]; char** pstr2 = str2;

'str2' is not 'char**' but char (*)[2];

so it must be corrected like this:
char (*pstr2)[2] = str2;

2. str2[0] = str; str2[1] = str3;

according to your codes, str2[0] and str2[1]
is not l-value and they cannot be placed left
side of '='.
Hee S. Chung
heesc@netian.com
 
char **argc --- means its a pointer to a pointer for a data type of character type. You can visualize **argc as two dimensional array ( argc[][] } where n number of strings of each variable length can be stored.

-Raghu
gmraghu@yahoo.com
 
I think u should definitely goto FAQ205-924 atleast once :) Ankan.

Please do correct me if I am wrong. s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top