#include<stdio.h>
int main(int argc,char *argv[]) {
printf("%c",++**++argv);
return 0;
}
Suppose the command line arguments passed were:
./a.out one two three
The output is:
p
Can someone please explain me what is happening?
#include<stdio.h>
int main(int argc,char *argv[]) {
printf("%c",++**++argv);
return 0;
}
Suppose the command line arguments passed were:
./a.out one two three
The output is:
p
Can someone please explain me what is happening?
Start from the back of the ++**++argv
expression:
argv
starts off as a pointer to element zero, i.e. "./a.out"
or ""
++argv
is char**
that points to string "one"
*++argv
is char*
that points to string "one"
's initial element**++argv
is char
that is equal to string "one"
s initial element, i.e. 'o'
++**++argv
is char
that follows 'o'
. On most systems that's 'p'
.The last operation modifies program's arguments in place, which is allowed by the standard (Q&A).