What is this "int *argc" and "char *argv[]" in arguments of main()?

I had a chance to look at the codes of some (small-time) professional software, written in C++.
In almost all the main() functions there are these two parameters. Like

1
2
3
4
int main(int *argc, char *argv[])
{
    //...
}


Also, had a look at a few tutorials on programming with GTK+ and QT etc etc, and they have the same trend there... I was under the impression that these might be the pointers to the containers which hold the command line arguments like switches and options... But I am not sure. (Although I use that line for style, :P... A simple int main() looks way less fashionable.)

Would someone clear the mystery please?
Last edited on
First parameter (which is of type int, not int*) contains the number of elements in the second one, which is an array of C strings containing the program arguments (first is the program name, though).
Last edited on
So if I want to see it in practice? Is that possible... Like running the program with command line arguments and having the argv and argc printed?
1
2
3
4
5
6
7
8
9
#include <iostream>

int main(int argc, char *argv[])
{
    for(int i = 0; i < argc; ++i)
    {
        std::cout << argv[i] << std::endl;
    }
}
Wow! Coooool!
Thanks... :)
Topic archived. No new replies allowed.