none
Question Header --> int main( int argc, char * const argv[] ) {

    Question

  • Hi,

     

    I have seen this in the main function in a program I got online.  Why does it pas argc and argv[], through the main function.  These two variables are not used anywhere in the function

     

    I noticed that this appears automatically when you create certain projects in C++.

    Visual Studio express 2008 sp1, windows xp

    Thanks

    Monday, March 22, 2010 12:42 AM

Answers

  • This is the standard means for command line parameters to be passed into C and C++ functions.

     

    This is usually listed as:

     

    int main(int argc, const char*argv[])

    {

    }

     

    argc will be the number of arguments, and each individual argument will be one element in argv.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, March 22, 2010 12:51 AM
  • Arguments to main
    http://msdn.microsoft.com/en-us/library/k104fy6h.aspx

    main: Program Startup
    http://msdn.microsoft.com/en-us/library/6wd819wh(VS.100).aspx

    - Wayne
    Monday, March 22, 2010 2:14 AM
  • As to why it is in te program but never used, who knows. It could be seen as good practice by the programmer.
    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    Monday, March 22, 2010 2:31 AM

All replies

  • This is the standard means for command line parameters to be passed into C and C++ functions.

     

    This is usually listed as:

     

    int main(int argc, const char*argv[])

    {

    }

     

    argc will be the number of arguments, and each individual argument will be one element in argv.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    Monday, March 22, 2010 12:51 AM
  • Arguments to main
    http://msdn.microsoft.com/en-us/library/k104fy6h.aspx

    main: Program Startup
    http://msdn.microsoft.com/en-us/library/6wd819wh(VS.100).aspx

    - Wayne
    Monday, March 22, 2010 2:14 AM
  • As to why it is in te program but never used, who knows. It could be seen as good practice by the programmer.
    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    Monday, March 22, 2010 2:31 AM