cincrementdecrement

Pointer Increment and Decrement(*--*++p) in c


#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 ?


Solution

  • In **++p;:

    In the *--*++p+2 in the printf:

    Then this pointer to the 4 character is passed to printf. The characters starting at that point are 4, 2, 3, 2, 1, and a null character, so printf prints 42321.