Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Duplicate:
What is the proper declaration of main?

What do we mean by the arguments in this main function? What are they trying to tell us?

int main(int argc, char** argv)

UPDATE: And, is the preceding line of code similar to this int main(int argc, char* argv[])? If so, how can we say that char** argv is similar to char* argv[] as they don't look similar from an array point of view?

How is it compared with int main() which does not have any arguments?

Thanks.

like image 503
Simplicity Avatar asked Mar 04 '11 09:03

Simplicity


People also ask

How to call main () with arguments passed to INT argc?

Suppose you run your program thus (using sh syntax): If you declared your main as int main (int argc, char *argv []), then (in most environments), your main () will be called as if like: However, if you declared your main as int main (), it will be called something like and you don't get the arguments passed.

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

What does int argc, char *argv [] mean in C/C++? C C++ Server Side Programming Programming argc stands for argument count and argv stands for argument values. These are variables passed to the main function when it starts executing.

What is the use of int main in C++?

int main (int argc, char* argv []); This declaration is used when your program must take command-line arguments. When run like such: myprogram arg1 arg2 arg3. argc, or Argument Count, will be set to 4 (four arguments), and argv, or Argument Vectors, will be populated with string pointers to "myprogram", "arg1", "arg2", and "arg3".

How to use command-line arguments (argc and argv) in C?

This article will explain several methods of using command-line arguments, argc and argv, in C. When a program gets executed, the user can specify the space-separated strings called command-line arguments. These arguments are made available in the program’s main function and can be parsed as individual null-terminated strings.


1 Answers

The argc parameter is the number of command line options specified, including the executable name, when the executable was invoked. The individual command line options are found in the argv array, which is NULL terminated (the name and path used to invoke the executable is in argv[0]).

The difference between the two versions is simply if you want to parse command line arguments or not - if you are not interested in them then you can ignore them using the second form.

like image 50
trojanfoe Avatar answered Sep 27 '22 21:09

trojanfoe