Thread: char**

  1. #1
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    char**

    Sorry to ask so many questions, but what does char**, as in int main (int argc, char **argv), mean?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Well char** means a pointer to a pointer im not to sure what it means in that case though im sure someone here knows that part
    Woop?

  3. #3
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    char * is the definition of a character string, and is the same as char[]. char ** is in effect a pointer to an array of strings, or char[][]. Basically the char ** stores the command line paramaters you give the program. So if you call for example ping 999.999.9.999 -s -a
    you would have an argv of three (three arguments on the paramater list) and an argc** would be "999.999.9.999","-s","-a", strings that carry the actual paramaters.
    Last edited by Draco; 08-09-2004 at 10:34 AM.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    char[] and char * are not always the same. And passing a char[][] is not the same as char**.

    As prog-bman stated char ** is a pointer to a pointer to a character.

    When accepting an array you have a choice of syntax to use
    (<type> *) or (<type> [])

    Now when you load the program an array of pointers to characters is loaded for any arguments and main() can accept them. So you have a couple choices:
    char *argv[] or char **argv
    it might seem confusing but its just as above with the <type>. The type on this one is char *

  5. #5
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    Gotcha

    OK cool. Thanks for the info - I don't know why I didn't see that. What is the difference, then, between using char* and using char[]? Is it that char* is dynamic and char[] is static?

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    it depends where you use it

    In a function header or prototype there is no difference, the [] was put in for convience.

  7. #7
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Quote Originally Posted by Draco
    So if you call for example ping 999.999.9.999 -s -a
    you would have an argv of three (three arguments on the paramater list) and an argc** would be "999.999.9.999","-s","-a", strings that carry the actual paramaters.
    You would actually have an argc of 4 (an argument count of 4) along with an array of 4 character strings in argv:

    argv[0]: ping
    argv[1]: 999.999.9.999
    argv[2]: -s
    argv[3]: -a

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed