Thread: int main(int argc, char *argv[])

  1. #1
    Registered User
    Join Date
    May 2010

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

    Hello fellow programmers, i started learning about the parameters in int main() and it confused me because i dont know what they are and what they're used for.So if you could give me some info or some sample code and explain how it is used or what it is.

    Thank you

  2. #2
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    A quick search on the web resulted in this: The GNU C Programming Tutorial
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  3. #3
    The Autodidact Dante Wingates's Avatar
    Join Date
    Apr 2010
    they are the command line parameters... Im not sure how they call it in english but let me try to explain it...

    When you execute a program on the command prompt, you pass some values to it... For example "program.exe blabla" executes program.exe and pass "blabla" to it as an command line argument. It then uses this argument to make its processing

    Now that is exactly what those parameters are.. The int argc holds the number of string parameters in argv. *Argv[] is a pointer to a multi dimensional array, or a pointer to a pointer as I like to call it... the first element in argv in always the programs path and name, including the extension... You could also use **argv instead of *argv[]... Here, I'll give you an example

    #include <iostream>
    int main(int argc, char **argv)
        std::cout << *argv;
    this program will take the first element in argv and then print it... The first element is the programs path... argc says how much elements there are in argv.

    There can be also more parameters, but you dont need to worry about it now.

  4. #4
    Join Date
    Dec 2009
    argc = number of args in argv
    argv = arrary of char arrays

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Producer/Consumer - problems creating threads
    By hansel13 in forum C Programming
    Replies: 47
    Last Post: 08-20-2010, 02:02 PM
  2. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. I need help with variables, please
    By JOCAAN in forum C++ Programming
    Replies: 39
    Last Post: 12-08-2007, 04:16 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM