1

Since argv is an array of pointers to char, and string is a char array underneath, what's the rational behind storing an array of points to the strings passed into the program?

I thought that a use of a pointer made sense if you wished to change what was being pointed to, so I don't understand why you'd want pointers in the case of program arguments.

  • 1
    It comes from old C, there was no string like in c++. – T0maas Nov 28 '21 at 22:16
  • On the one hand, that is *far* from the only use-case for pointers. – sweenish Nov 28 '21 at 22:16
  • @T0maas if the function definition of `main` changes the type of `argv`, does it all break? Why not just retype it to modern C++ types? Further, does the C++ spec require the function to have the declaration it has or can `main` not be overloaded? My C++ experience isn't much so I'm not fully acclimated with the spec. –  Nov 28 '21 at 22:21
  • 1
    @madeslurpy See [Is main() overloaded in C++?](https://stackoverflow.com/a/6408230/11082165). main cannot be overloaded, and there are only two valid signatures that it can have. – Brian61354270 Nov 28 '21 at 22:25
  • @madeslurpy if you think something like this: int main(int argc, std::string argv[]) {}. That will not work. – T0maas Nov 28 '21 at 22:28

0 Answers0