int main (int argc, int argv). What does it means | SoloLearn: Learn to code for FREE!

+15

int main (int argc, int argv). What does it means

c++

8/5/2019 5:32:40 PM

Ibrohim

7 Answers

New Answer

+11

ibrohim What you have written is wrong. It should be int main(int argc, char *argv[]) or int main(int argc, char **argv) This is another form of main function in C/C++. This is used when you want to pass some data to your program when launching it from command line, script file or other programs. argc is the no of parameters passed to the main function and argv is an array of C style strings containing the actual arguments passed. So say your program name is myprog. Then if you launch your program from command line like myprog 1 2 3 then argc will equal to 4 meaning 4 parameters passed, this is because the first parameter is always the full path of the program including the name from where it was launched. So argv[0] = "full path of the program" argv[1] = 1 argv[2] = 2 argv[3] = 3

+9

thank you

+5

Here are some similar questions : https://www.sololearn.com/Discuss/1496388/?ref=app https://www.sololearn.com/Discuss/1770867/?ref=app but none of the answers in them seem as clear as ~ swim ~ 's one here.

+5

it's the basis for command line argument...

+4

ibrohim 👍🙂

+4

Basically it is arg[ument]c[ounter] arg[ument]v[alues]

+4

Sonic 👍🙂🙏