argv is an array pointers to strings, last pointer is null.
Suppose your executable name is exe and you run it like:
$ exe fist second
then argv is:
+----------+
argv---â–ş| "exe" |
+----------+
argv + 1---â–ş| "first" |
+----------+
argv + 2---â–ş| "second" |
+----------+
argv + 3---â–ş| null |
+----------+
* Notice last is null.
So char** input = argv + 1 points to "first" string that is first input argument.
if your prints argv[0] with %s output will be "exe" that is your executable name and if you prints input[0] with %s output will be "fisrt" string.
Note: even if you don't pass any argument intput will point to NULL (valid address).
(purpose of this is to point to input arguments strings, or say skip program name "exe")
My following code example, and its set of outputs will help you to understand.
code.c:
#include<stdio.h>
int main(int argc, char* argv[]){
char** input = argv + 1;
while(*input) /* run untill input-->null */
printf("%s \n", *input++);
return 1;
}
outputs:
~$ gcc code.c -Wall -pedantic -o exe
~$ ./exe
~$ ./exe first
first
~$ ./exe first second
first
second
inputs = &argv[1]less confusing?argvis an array of pointers andargvrepresents the address of the*argv[0]so I think you can absolutely assign it like that.argv[1]would be equivalent to*(argv+1), not equivalent toargv+1. In other words,argv+1is a pointer toargv[1].