Here's the code:
char* a[] = {"ls", "-l", "|", "grep", "test"};
int pipe_idx = 2;
char** ptr2 = a + (pipe_idx * sizeof(char**));
printf("%s\n", *ptr2);
Basically, this is just a demo code. The program gets the pipe_index (in this case it's 2
) and jumps to the right place, and then print it.
Why do I get segmentation fault?