Can somebody please tell me how can you call function main, cause as I see there are parameters that can be passed (an int and an array).
What is it used for? I hear it is for the command line, but no idea as to what effects it has on the program.
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The parameters are not required. You can define either:
int main() ...
or:
int main(int argc, char* argv[]) ...
You are talking about the second case. The first parameter 'argc' tells you the number of string tokens present on the command line, so when you type something like this to start your program:
myprogram parm1 parm2
...your program will start with argc equal to 3. This means that you started it with three string tokens: the name of the program itself plus two parameters.
The argv parameter is an array that contains three pointers to each of these tokens so that your program knows what its own name is as well as what the three parameters are. You can print the value of these tokens using these pointers, so argv[0] points to the program name "myprogram", argv[1] points to "param1" and argv[2] points to "param2".
It's up to you to do whatever you want with these values in your program. You can also ignore them.
qWake
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can somebody please tell me how can you call function main, cause as I see there are parameters that can be passed (an int and an array).
What is it used for? I hear it is for the command line, but no idea as to what effects it has on the program.
Thanks in advance.
The parameters are not required. You can define either:
int main() ...
or:
int main(int argc, char* argv[]) ...
You are talking about the second case. The first parameter 'argc' tells you the number of string tokens present on the command line, so when you type something like this to start your program:
myprogram parm1 parm2
...your program will start with argc equal to 3. This means that you started it with three string tokens: the name of the program itself plus two parameters.
The argv parameter is an array that contains three pointers to each of these tokens so that your program knows what its own name is as well as what the three parameters are. You can print the value of these tokens using these pointers, so argv[0] points to the program name "myprogram", argv[1] points to "param1" and argv[2] points to "param2".
It's up to you to do whatever you want with these values in your program. You can also ignore them.
qWake
Thanks!