argc and argv are the variables that C and C++ use for passing arguments to a program on the command-line. If you look at the beginning of the main() function, there should be something along the lines of:
Code:
main( int argc, char ** argv )
argc is an integer that contains the number of arguments passed to the program. argv is an array of character arrays which contains the value of each argument. So, say your program is called 'foo', and you run it by typing:
foo a b c
Then argc is equal to three (since there are three arguments, separated by spaces), and argv contains the following:
argv[0]: "foo"
argv[1]: "a"
argv[2]: "b"
argv[3]: "c"
So, to answer your question, when the program compares argc to some number like 2, it's asking "did the user give enough arguments to run the program correctly? If not, print a message about how to use the program correctly."
Did all that make sense?
To understand it better, you could try writing a simple program to print the values of arguments. Try this (in C++):
Code:
int main( int argc, char ** argv )
{
for ( int i = 0; i <= argc; i++ )
cout << "argv[" << i << "]: " << argv[i] << endl;
return 0;
}
Compile and run this with various arguments to see what happens.