-4

I am watching a video about how to build a Hash table, but from the beginning there is a line that I don't understand:

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

What does "char**" mean?

Thanks in advance.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Roshan
  • 27
  • 4
  • 8
    Possible duplicate of [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Bartek Banachewicz Dec 15 '15 at 11:00
  • 4
    It means a pointer to a pointer to a character. HTH. – Tony Delroy Dec 15 '15 at 11:00
  • @TonyD thanks, one more thing, isn't that strange to define inputs for the main function? – Roshan Dec 15 '15 at 11:05
  • @Roshan: no. When people run a program, they can pass arguments on the command line. That's what the `argv` is for: `argv[0]` is nominally the name of the program, `argv[1]` is the first space-separated word in the argument list - if any. Each `argv[i]` entry is a `char*` to an ASCIIZ copy of the word from the command line. `argc` tells you how many words were on the command line, plus one for the program name. Every single C++ program that handles command line arguments will have this signature, which is why practically *any* introductory C++ book covers this. – Tony Delroy Dec 15 '15 at 11:07
  • @TonyD, The explanations was perfect, Thanks so much. – Roshan Dec 15 '15 at 11:15

1 Answers1

0

That is one of the allowable function signatures for the designated start of the program.

It is a requirement of a C++ executable that it contain one and only one of:

  1. int main()
  2. int main(int argc, char** argv) (This function signature of main is allowed to take additional parameters.)

You can find more information about main here: http://en.cppreference.com/w/cpp/language/main_function

To specifically quote the definition of argv:

Pointer to the first element of an array of pointers to null-terminated multibyte strings that represent the arguments passed to the program from the execution environment (argv[0] through argv[argc-1]). The value of argv[argc] is guaranteed to be ​0​.

For a more detailed documentation of how Microsoft populates argv you can see here: https://msdn.microsoft.com/en-us/library/17w5ykft.aspx

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288