php hit counter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why we write main rgc,char**argv in C++ 2012
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
Why we write main(argc,char**argv) what is its use ?when we use it and what is its meaning? please explain it with some example

C and C++ have a special argument list for main( ), which looks like this:

int main(int argc, char* argv[]) { // ...

The first argument is the number of elements in the array, which is the second argument. The second argument is always an array of char*, because the arguments are passed from the command line as character arrays (and remember, an array can be passed only as a pointer). Each whitespace-delimited cluster of characters on the command line is turned into a separate array argument. The following program prints out all its command-line arguments by stepping through the array:

Example:

int main(int argc, char* argv[]) {

cout << "argc = " << argc << endl;

for(int i = 0; i < argc; i++)

cout << "argv[" << i << "] = "

<< argv[i] << endl;

}

You’ll notice that argv[0] is the path and name of the program itself. This allows the program to discover information about itself. It also adds one more to the array of program arguments, so a common error when fetching command-line arguments is to grab argv[0] when you want argv[1].

You are not forced to use argc and argv as identifiers in main( ); those identifiers are only conventions (but it will confuse people if you don’t use them). Also, there is an alternate way to declare argv:

int main(int argc, char** argv) { // ...

Both forms are equivalent

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 3,068 05-31-2012, 01:40 AM
Last Post: Vuhelper
  what is meant by trivial and non trivial in C and C++ 2012 Vuhelper 0 4,119 05-31-2012, 01:38 AM
Last Post: Vuhelper
  how can i mail you the snapshot of compiled files.in C++ 2012 Vuhelper 0 2,930 05-31-2012, 01:32 AM
Last Post: Vuhelper
  what is main logic behind turning a register into byte count other than multiplying 2 Vuhelper 0 2,873 05-31-2012, 01:29 AM
Last Post: Vuhelper
  protected inheritance and abstract classes in C++ 2012 Vuhelper 0 1,771 01-14-2012, 05:48 PM
Last Post: Vuhelper
  std::cout<<"---"; " and also for cin " std::cin>>x; in C++ 2012 Vuhelper 0 3,211 01-14-2012, 05:46 PM
Last Post: Vuhelper
  program Output in C++ 2012 Vuhelper 0 3,035 01-06-2012, 12:28 AM
Last Post: Vuhelper
  Threaded Binary Tree? in C++ 2012 Vuhelper 0 3,546 01-06-2012, 12:25 AM
Last Post: Vuhelper
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 2,001 01-06-2012, 12:24 AM
Last Post: Vuhelper
  What is the difference b/w Inorder Traversal and Inorder Successor? 2012 Vuhelper 0 1,835 01-06-2012, 12:23 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support