Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

What does int argc, char *argv[] mean in C/C++?

What does int argc, char *argv[] mean in C/C++?


1 Answer
Chandu yadav

argc stands for argument count and argv stands for argument values. These are variables passed to main function when it starts executing. When we run a program we can give arguments to that program like:

$ ./a.out hello

Here hello is an argument to the enecutable. This can be accessed in your program. For example,

#include<iostream>
using namespace std;
int main(int argc, char** argv) {
   cout << "This program has " << argc << " arguments:" << endl;
   for (int i = 0; i < argc; ++i) {
      cout << argv[i] << endl;
   }
   return 0;
}

When you compile and run this program like:

$ ./a.out hello people

This will give the output:

This program has 3 arguments

C:\Users\user\Desktop\hello.exe
hello
people

Note that the first argument is always the location of the executable executing.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.