It will be helpful to create the following temporary variables to understand some of the expressions.
char s1[] = "GeksQuiz";
char s2[] = "MCQ";
char s3[] = "TEST";
char s4[] = "QUIZ";
char *c[] = {s1, s2, s3, s4};
char **cp[] = {c+3, c+2, c+1, c};
char ***cpp = cp;
First printf
printf("%s ", **++cpp);
**++cpp
has the side effect of cpp = cpp+1
, and evaluates to
**(cpp+1)
, which is the same as
*(cp[1])
, which is the same as
*(c+2)
, which is the same as:
c[2]
, which is the same as:
s3
, which evaluates to "TEST"
.(initially it was s2 corrected)
At the end of that statement, cpp
is the same as cp+1
.
Second printf
printf("%s ", *--*++cpp+3);
*--*++cpp+3
is the same as
*(--(*(++cpp))) + 3
, has side effect of cpp = cpp+1
, and evaluates to:
*(--(*(cpp+1))) + 3
, which is the same as
*(--(*(cp+2))) + 3
, which is the same as
*(--(cp[2])) + 3
*(--(cp[2])) + 3
has the side effect of cp[2] = cp[2]-1 = c+1-1 = c
, and evaluates to:
*(cp[2]-1) + 3
, which is the same as
*(c+1-1) + 3
, which is the same as
*(c) + 3
, which is the same as
c[0] + 3
, which is the same as
s1 + 3
, which evaluates to "sQuiz"
At the end of that statement, cpp
is the same as cp+2
.
Third printf
printf("%s ", *cpp[-2]+3);
*cpp[-2]+3
is the same as
*(cpp[-2])+3
, which is the same as
*(cp)+3
because of the previous ++
operations on cpp
., which is the same as
c[3]+3
, which is the same as
s4+3
, which evaluates to "Z"
.(corrected initially it was s3+3)
Fourth printf
printf("%s ", cpp[-1][-1]+1);
cpp[-1][-1]+1
is the same as
*(cpp-1)[-1]+1
, which is the same as
*(*(cpp-1) -1) + 1
, which is the same as
*(*(cp+1) -1) + 1
, which is the same as
*(cp[1] -1) + 1
, which is the same as
*(c+2-1) + 1
, which is the same as
*(c+1) + 1
, which is the same as
c[1] + 1
, which is the same as
s2 + 1
, which evaluates to "CQ"
.