C++ - char** argv vs. char* argv[]

后端 未结 7 1200
别跟我提以往
别跟我提以往 2020-12-12 12:09

What is the difference between char** argv and char* argv[]? in int main(int argc, char** argv) and int main(int argc, char* arg

7条回答
  •  天涯浪人
    2020-12-12 12:56

    Both are same for your usage except for the following subtle differences:

    • Sizeof will give different results for both
    • Also second one may not be reassigned to new memory area since it's an array
    • With second one you can use only those indexes which are valid. It's unspecified by C/C++ if you try to use an array index beyond array length. However with char** you can use any index from 0 to ...
    • Second form can only be used as formal parameters to a function. While first can even be used to declare variables within a stack.

提交回复
热议问题