#include <stdio.h>
int main() {
static char*s[] = {"6642321","93456","134098","55513"};
char ** str[] = {s+3,s+2,s+1,s};
char ***p = str;
**++p;
printf("%s\n",*--*++p+2);
return 0;
}
In this code on the printf statement *++p gives one address(s+1). In my understanding --(s+1) gives compilation error. But this code gives output as 42321. Why I am getting this answer. Please could anyone explain this code ?
In
**++p;:++pincrementspso it points tostr+1instead of its initial value,str.*produces the elementppoints to (after the increment), and that isstr[1].*produces the element thatstr[1]points to, and that is*(s+2)or, equivalently,s[2].In the
*--*++p+2in theprintf:++pincrementspso it points tostr+2.*produces the elementppoints to, and that isstr[2].--decrementsstr[2], so it changes froms+1tos+0, or justs.*produces the elementstr[2]points to (after the decrement), so it produces*sor, equivalently,s[0].s[0]is a pointer to the first character of"6642321".+2produces a pointer to two characters beyond this, so it points to the4character.Then this pointer to the
4character is passed toprintf. The characters starting at that point are4,2,3,2,1, and a null character, so printf prints42321.