Why C/C++ main argv is declared as “char* argv[]” rather than just “char* argv”












2















Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv), why is the notion of "pointer to pointer" required here?










share|improve this question







New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    "a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

    – Sebastian Redl
    55 mins ago


















2















Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv), why is the notion of "pointer to pointer" required here?










share|improve this question







New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    "a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

    – Sebastian Redl
    55 mins ago
















2












2








2








Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv), why is the notion of "pointer to pointer" required here?










share|improve this question







New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Why is argv declared as "a pointer to pointer to the first index of the array", rather than just being "a pointer to the first index of array" (char* argv), why is the notion of "pointer to pointer" required here?







c++ c






share|improve this question







New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









a usera user

112




112




New contributor




a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






a user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1





    "a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

    – Sebastian Redl
    55 mins ago
















  • 1





    "a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

    – Sebastian Redl
    55 mins ago










1




1





"a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

– Sebastian Redl
55 mins ago







"a pointer to pointer to the first index of the array" - That's not a correct description of char* argv or char**. That's a pointer to a pointer to a character; specifically the outer pointer points to the first pointer in an array, and the inner pointers point to the first characters of nul-terminated strings. There's no indices involved here.

– Sebastian Redl
55 mins ago












4 Answers
4






active

oldest

votes


















3














Argv is basically like this:



enter image description here



So on the left is the argument itself--what's actually passed as a parameter to main. That contains the address of an array of pointers. Each of those points to some place in memory containing the text of the corresponding argument that was passed on the command line. Then, at the end of that array there's guaranteed to be a null pointer.



Note that the actual storage for the individual arguments are at least potentially allocated separately from each other, so their addresses in memory might be arranged fairly randomly (but depending on how things happen to be written, they could also be in a single contiguous block of memory--you simply don't know or and shouldn't care).






share|improve this answer































    3














    Because that's what the operating system provides :-)



    Your question is a little bit of a chicken/egg inversion issue. The problem is not to choose what you want in C++, the problem is how you say in C++ what the OS is giving you.



    Unix passes an array of "strings", each string being a command argument. In C/C++, a string is a "char*", so an array of strings is char* argv, or char** argv, according to taste.






    share|improve this answer








    New contributor




    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




























      2














      First, as a parameter declaration, char **argv is the same as char *argv; they both imply a pointer to (an array or set of one or more possible) pointer(s) to strings.



      Next, if you only have "pointer to char" (e.g. just char *, then in order to access the nth item, you'll have to scan the first n-1 items to find the nth item's start.  (And this would also impose the requirement that each of the strings are stored contiguously.)



      With the array of pointers, you can directly index the nth item — so (while not strictly necessary — assuming the strings are contiguous) it is generally much more convenient.



      To illustrate:



      ./program hello world



      argc = 3
      argv[0] --> "./program"
      argv[1] --> "hello"
      argv[2] --> "world"


      It is possible that, in string:
      "./programhelloworld"
      argv[0] ^
      argv[1] ^
      argv[2] ^



      if argv were just a "pointer to char" you might see



             "./programhelloworld"
      argv ^


      However (though likely by design of the os) there is no real guarantee that the three strings "./program", "hello", and "world" are contiguous.  Further, this kind of "single pointer to multiple contiguous strings" is a more unusual data type construct (for C), especially compared with array of pointers to string.






      share|improve this answer


























      • what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

        – a user
        6 hours ago













      • @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

        – Deduplicator
        6 hours ago













      • @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

        – Erik Eidt
        55 mins ago











      • @Deduplicator, of course, good point.

        – Erik Eidt
        55 mins ago











      • You forgot to state that in your example argv[4] is NULL

        – Basile Starynkevitch
        20 mins ago



















      1














      Rather than thinking of it as "pointer to pointer", it helps to think of it as "array of strings", with denoting array and char* denoting string. When you run a program, you can pass it one or more command-line arguments and these are reflected in the arguments to main: argc is the count of arguments and argv lets you access individual arguments.






      share|improve this answer























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "131"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });






        a user is a new contributor. Be nice, and check out our Code of Conduct.










        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f385819%2fwhy-c-c-main-argv-is-declared-as-char-argv-rather-than-just-char-argv%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        Argv is basically like this:



        enter image description here



        So on the left is the argument itself--what's actually passed as a parameter to main. That contains the address of an array of pointers. Each of those points to some place in memory containing the text of the corresponding argument that was passed on the command line. Then, at the end of that array there's guaranteed to be a null pointer.



        Note that the actual storage for the individual arguments are at least potentially allocated separately from each other, so their addresses in memory might be arranged fairly randomly (but depending on how things happen to be written, they could also be in a single contiguous block of memory--you simply don't know or and shouldn't care).






        share|improve this answer




























          3














          Argv is basically like this:



          enter image description here



          So on the left is the argument itself--what's actually passed as a parameter to main. That contains the address of an array of pointers. Each of those points to some place in memory containing the text of the corresponding argument that was passed on the command line. Then, at the end of that array there's guaranteed to be a null pointer.



          Note that the actual storage for the individual arguments are at least potentially allocated separately from each other, so their addresses in memory might be arranged fairly randomly (but depending on how things happen to be written, they could also be in a single contiguous block of memory--you simply don't know or and shouldn't care).






          share|improve this answer


























            3












            3








            3







            Argv is basically like this:



            enter image description here



            So on the left is the argument itself--what's actually passed as a parameter to main. That contains the address of an array of pointers. Each of those points to some place in memory containing the text of the corresponding argument that was passed on the command line. Then, at the end of that array there's guaranteed to be a null pointer.



            Note that the actual storage for the individual arguments are at least potentially allocated separately from each other, so their addresses in memory might be arranged fairly randomly (but depending on how things happen to be written, they could also be in a single contiguous block of memory--you simply don't know or and shouldn't care).






            share|improve this answer













            Argv is basically like this:



            enter image description here



            So on the left is the argument itself--what's actually passed as a parameter to main. That contains the address of an array of pointers. Each of those points to some place in memory containing the text of the corresponding argument that was passed on the command line. Then, at the end of that array there's guaranteed to be a null pointer.



            Note that the actual storage for the individual arguments are at least potentially allocated separately from each other, so their addresses in memory might be arranged fairly randomly (but depending on how things happen to be written, they could also be in a single contiguous block of memory--you simply don't know or and shouldn't care).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 4 hours ago









            Jerry CoffinJerry Coffin

            40.1k574148




            40.1k574148

























                3














                Because that's what the operating system provides :-)



                Your question is a little bit of a chicken/egg inversion issue. The problem is not to choose what you want in C++, the problem is how you say in C++ what the OS is giving you.



                Unix passes an array of "strings", each string being a command argument. In C/C++, a string is a "char*", so an array of strings is char* argv, or char** argv, according to taste.






                share|improve this answer








                New contributor




                passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.

























                  3














                  Because that's what the operating system provides :-)



                  Your question is a little bit of a chicken/egg inversion issue. The problem is not to choose what you want in C++, the problem is how you say in C++ what the OS is giving you.



                  Unix passes an array of "strings", each string being a command argument. In C/C++, a string is a "char*", so an array of strings is char* argv, or char** argv, according to taste.






                  share|improve this answer








                  New contributor




                  passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.























                    3












                    3








                    3







                    Because that's what the operating system provides :-)



                    Your question is a little bit of a chicken/egg inversion issue. The problem is not to choose what you want in C++, the problem is how you say in C++ what the OS is giving you.



                    Unix passes an array of "strings", each string being a command argument. In C/C++, a string is a "char*", so an array of strings is char* argv, or char** argv, according to taste.






                    share|improve this answer








                    New contributor




                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.










                    Because that's what the operating system provides :-)



                    Your question is a little bit of a chicken/egg inversion issue. The problem is not to choose what you want in C++, the problem is how you say in C++ what the OS is giving you.



                    Unix passes an array of "strings", each string being a command argument. In C/C++, a string is a "char*", so an array of strings is char* argv, or char** argv, according to taste.







                    share|improve this answer








                    New contributor




                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer






                    New contributor




                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 3 hours ago









                    passer-bypasser-by

                    311




                    311




                    New contributor




                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    passer-by is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.























                        2














                        First, as a parameter declaration, char **argv is the same as char *argv; they both imply a pointer to (an array or set of one or more possible) pointer(s) to strings.



                        Next, if you only have "pointer to char" (e.g. just char *, then in order to access the nth item, you'll have to scan the first n-1 items to find the nth item's start.  (And this would also impose the requirement that each of the strings are stored contiguously.)



                        With the array of pointers, you can directly index the nth item — so (while not strictly necessary — assuming the strings are contiguous) it is generally much more convenient.



                        To illustrate:



                        ./program hello world



                        argc = 3
                        argv[0] --> "./program"
                        argv[1] --> "hello"
                        argv[2] --> "world"


                        It is possible that, in string:
                        "./programhelloworld"
                        argv[0] ^
                        argv[1] ^
                        argv[2] ^



                        if argv were just a "pointer to char" you might see



                               "./programhelloworld"
                        argv ^


                        However (though likely by design of the os) there is no real guarantee that the three strings "./program", "hello", and "world" are contiguous.  Further, this kind of "single pointer to multiple contiguous strings" is a more unusual data type construct (for C), especially compared with array of pointers to string.






                        share|improve this answer


























                        • what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                          – a user
                          6 hours ago













                        • @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                          – Deduplicator
                          6 hours ago













                        • @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                          – Erik Eidt
                          55 mins ago











                        • @Deduplicator, of course, good point.

                          – Erik Eidt
                          55 mins ago











                        • You forgot to state that in your example argv[4] is NULL

                          – Basile Starynkevitch
                          20 mins ago
















                        2














                        First, as a parameter declaration, char **argv is the same as char *argv; they both imply a pointer to (an array or set of one or more possible) pointer(s) to strings.



                        Next, if you only have "pointer to char" (e.g. just char *, then in order to access the nth item, you'll have to scan the first n-1 items to find the nth item's start.  (And this would also impose the requirement that each of the strings are stored contiguously.)



                        With the array of pointers, you can directly index the nth item — so (while not strictly necessary — assuming the strings are contiguous) it is generally much more convenient.



                        To illustrate:



                        ./program hello world



                        argc = 3
                        argv[0] --> "./program"
                        argv[1] --> "hello"
                        argv[2] --> "world"


                        It is possible that, in string:
                        "./programhelloworld"
                        argv[0] ^
                        argv[1] ^
                        argv[2] ^



                        if argv were just a "pointer to char" you might see



                               "./programhelloworld"
                        argv ^


                        However (though likely by design of the os) there is no real guarantee that the three strings "./program", "hello", and "world" are contiguous.  Further, this kind of "single pointer to multiple contiguous strings" is a more unusual data type construct (for C), especially compared with array of pointers to string.






                        share|improve this answer


























                        • what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                          – a user
                          6 hours ago













                        • @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                          – Deduplicator
                          6 hours ago













                        • @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                          – Erik Eidt
                          55 mins ago











                        • @Deduplicator, of course, good point.

                          – Erik Eidt
                          55 mins ago











                        • You forgot to state that in your example argv[4] is NULL

                          – Basile Starynkevitch
                          20 mins ago














                        2












                        2








                        2







                        First, as a parameter declaration, char **argv is the same as char *argv; they both imply a pointer to (an array or set of one or more possible) pointer(s) to strings.



                        Next, if you only have "pointer to char" (e.g. just char *, then in order to access the nth item, you'll have to scan the first n-1 items to find the nth item's start.  (And this would also impose the requirement that each of the strings are stored contiguously.)



                        With the array of pointers, you can directly index the nth item — so (while not strictly necessary — assuming the strings are contiguous) it is generally much more convenient.



                        To illustrate:



                        ./program hello world



                        argc = 3
                        argv[0] --> "./program"
                        argv[1] --> "hello"
                        argv[2] --> "world"


                        It is possible that, in string:
                        "./programhelloworld"
                        argv[0] ^
                        argv[1] ^
                        argv[2] ^



                        if argv were just a "pointer to char" you might see



                               "./programhelloworld"
                        argv ^


                        However (though likely by design of the os) there is no real guarantee that the three strings "./program", "hello", and "world" are contiguous.  Further, this kind of "single pointer to multiple contiguous strings" is a more unusual data type construct (for C), especially compared with array of pointers to string.






                        share|improve this answer















                        First, as a parameter declaration, char **argv is the same as char *argv; they both imply a pointer to (an array or set of one or more possible) pointer(s) to strings.



                        Next, if you only have "pointer to char" (e.g. just char *, then in order to access the nth item, you'll have to scan the first n-1 items to find the nth item's start.  (And this would also impose the requirement that each of the strings are stored contiguously.)



                        With the array of pointers, you can directly index the nth item — so (while not strictly necessary — assuming the strings are contiguous) it is generally much more convenient.



                        To illustrate:



                        ./program hello world



                        argc = 3
                        argv[0] --> "./program"
                        argv[1] --> "hello"
                        argv[2] --> "world"


                        It is possible that, in string:
                        "./programhelloworld"
                        argv[0] ^
                        argv[1] ^
                        argv[2] ^



                        if argv were just a "pointer to char" you might see



                               "./programhelloworld"
                        argv ^


                        However (though likely by design of the os) there is no real guarantee that the three strings "./program", "hello", and "world" are contiguous.  Further, this kind of "single pointer to multiple contiguous strings" is a more unusual data type construct (for C), especially compared with array of pointers to string.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 54 mins ago

























                        answered 7 hours ago









                        Erik EidtErik Eidt

                        22.7k43158




                        22.7k43158













                        • what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                          – a user
                          6 hours ago













                        • @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                          – Deduplicator
                          6 hours ago













                        • @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                          – Erik Eidt
                          55 mins ago











                        • @Deduplicator, of course, good point.

                          – Erik Eidt
                          55 mins ago











                        • You forgot to state that in your example argv[4] is NULL

                          – Basile Starynkevitch
                          20 mins ago



















                        • what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                          – a user
                          6 hours ago













                        • @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                          – Deduplicator
                          6 hours ago













                        • @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                          – Erik Eidt
                          55 mins ago











                        • @Deduplicator, of course, good point.

                          – Erik Eidt
                          55 mins ago











                        • You forgot to state that in your example argv[4] is NULL

                          – Basile Starynkevitch
                          20 mins ago

















                        what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                        – a user
                        6 hours ago







                        what if instead of , argv --> "helloworld" you have argv --> index 0 of the array (hello), just like a normal array. why isn't this doable? then you keep reading the array argc times. then you pass argv itself and not a pointer to argv.

                        – a user
                        6 hours ago















                        @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                        – Deduplicator
                        6 hours ago







                        @Erik They are the same thing in a function-declaration, not in general. Just try to declare some external variables.

                        – Deduplicator
                        6 hours ago















                        @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                        – Erik Eidt
                        55 mins ago





                        @auser, that's what argv --> "./programhelloworld" is: a pointer to the first char (i.e. the ".") If you take that pointer past the first , then you have a pointer to "hello", and after that to "world". After argc times (hitting "), you're done. Sure, it can be made to work, and as I said, an unusual construct.

                        – Erik Eidt
                        55 mins ago













                        @Deduplicator, of course, good point.

                        – Erik Eidt
                        55 mins ago





                        @Deduplicator, of course, good point.

                        – Erik Eidt
                        55 mins ago













                        You forgot to state that in your example argv[4] is NULL

                        – Basile Starynkevitch
                        20 mins ago





                        You forgot to state that in your example argv[4] is NULL

                        – Basile Starynkevitch
                        20 mins ago











                        1














                        Rather than thinking of it as "pointer to pointer", it helps to think of it as "array of strings", with denoting array and char* denoting string. When you run a program, you can pass it one or more command-line arguments and these are reflected in the arguments to main: argc is the count of arguments and argv lets you access individual arguments.






                        share|improve this answer




























                          1














                          Rather than thinking of it as "pointer to pointer", it helps to think of it as "array of strings", with denoting array and char* denoting string. When you run a program, you can pass it one or more command-line arguments and these are reflected in the arguments to main: argc is the count of arguments and argv lets you access individual arguments.






                          share|improve this answer


























                            1












                            1








                            1







                            Rather than thinking of it as "pointer to pointer", it helps to think of it as "array of strings", with denoting array and char* denoting string. When you run a program, you can pass it one or more command-line arguments and these are reflected in the arguments to main: argc is the count of arguments and argv lets you access individual arguments.






                            share|improve this answer













                            Rather than thinking of it as "pointer to pointer", it helps to think of it as "array of strings", with denoting array and char* denoting string. When you run a program, you can pass it one or more command-line arguments and these are reflected in the arguments to main: argc is the count of arguments and argv lets you access individual arguments.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 7 hours ago









                            casablancacasablanca

                            69437




                            69437






















                                a user is a new contributor. Be nice, and check out our Code of Conduct.










                                draft saved

                                draft discarded


















                                a user is a new contributor. Be nice, and check out our Code of Conduct.













                                a user is a new contributor. Be nice, and check out our Code of Conduct.












                                a user is a new contributor. Be nice, and check out our Code of Conduct.
















                                Thanks for contributing an answer to Software Engineering Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f385819%2fwhy-c-c-main-argv-is-declared-as-char-argv-rather-than-just-char-argv%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Ponta tanko

                                Tantalo (mitologio)

                                Erzsébet Schaár