int main(int argc, char *argv[])
. If you can assist me with this, I would greatly appreciate your timed effort.
The parentheses (()) followed by the word main tells the compiler that there is a function named main, and that the function returns an integer (whole number), hence int. Optionally, these parentheses may enclose a list of parameters within them. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. For that same reason, it is essential that all C++ programs have a main function. The curly braces ({}) signal the beginning and end of the functions and other code blocks.
This is a return statement that indicates that the program ended successfully. This ends execution of the executable program in the main function.
The function main is declared with the parameters, int argc, char *argv[] .Although any name can be given to these parameters, they are usually referred to as argc and argv. The first parameter, argc (argument count), has type int and indicates how many arguments were entered on the command line. The second parameter, argv (argument vector), has type array of pointers to char array objects. char array objects are null-terminated strings. The value of argc indicates the number of pointers in the array argv. If a program name is available, the first element in argv points to a character array that contains the program name or the invocation name of the program that is being run. If the name cannot be determined, the first element in argv points to a null character. This name is counted as one of the arguments to the function main. For example, if only the program name is entered on the command line, argc has a value of 1 and argv[0] points to the program name. Regardless of the number of arguments entered on the command line, argv[argc] always contains NULL. |
return
doesn't indicate that the program is exiting, it indicates that the function is exiting. In this case, it indicates that main() is exiting. It just so happens that when main exits, so does the program.If the name cannot be determined, the first element in argv points to a null character. |
myprogram.exe -someoption myfile.txt
|
|
Regardless of the number of arguments entered on the command line, argv[argc] always contains NULL. |