What is the difference between char** argv
and char* argv[]
? in int main(int argc, char** argv)
and int main(int argc, char* argv[])
?
Are they the same? Especially that the first part does not have []
.
The declaration char *argv[] is an array (of undetermined size) of pointers to char , in other words an array of strings. And all arrays decays to pointers, and so you can use an array as a pointer (just like you can use a pointer as an array).
What does int argc, char *argv[] mean in C/C++? CC++Server Side ProgrammingProgramming. argc stands for argument count and argv stands for argument values. These are variables passed to the main function when it starts executing. When we run a program we can give arguments to that program like − $ ./a.out hello.
Command-line Arguments: main( int argc, char *argv[] ) Here argc means argument count and argument vector. The first argument is the number of parameters passed plus one to include the name of the program that was executed to get those process running.
For the array, the total string is stored in the stack section, but for the pointer, the pointer variable is stored into stack section, and content is stored at code section. And the most important difference is that, we cannot edit the pointer type string.
They are entirely equivalent. char *argv[]
must be read as array of pointers to char
and an array argument is demoted to a pointer, so pointer to pointer to char
, or char **
.
This is the same in C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With