#include<stdio.h>
int main()
{
static char *a[] = {
"so", "how", "are", "you"
};
char *ptr[] = {a+3, a+2, a+1, a};
char ***p = ptr;
// Output 1
printf("%sn", **++p); // Outputs the string pointed to by p after incrementing p
// Output 2
printf("%sn", *--*++p+3); // This is the statement in question
return 0;
}
After executing First print p is pointing to ptr[1], so output 1 = “are”.
Current State of p:
After ++p, p points to ptr[2], which is a + 1.
Dereferencing *++p:
Dereferencing p (which is now a + 1) gives us a + 1. This points to the string “how”.
Applying — * ++p:
Decrementing a + 1 results in a. Thus, — * ++p points to a, which is the start of the string “so”.
Dereferencing * — *++p:
Dereferencing a gives us the string “so”.
Pointer Arithmetic * — *++p + 3:
Adding 3 to the pointer to “so” moves the pointer past the end of the string “so”. This points to the null terminator ”.
After My analysis Result:
The pointer points to the null terminator, so the result of * — *++p + 3 is an empty string.
But In compiler the output is coming as “how”(output 2) What mistake I might be doing?
2