Hello, I read from a book exercise for a challenge. How to print out each letter of char array a[][][] by two different pointers pa and ppa in the example?
I have tried my code for letter "r" by testing without full understanding as only the first one worked.
#include<stdio.h>
int main()
{
char a[4][3][2] = { {{'a', 'b'}, {'c', 'd',}, {'e', 'f'}},
{{'g', 'h'}, {'i', 'j'}, {'k', 'l'}},
{{'m', 'n'}, {'o', 'p'}, {'q', 'r'}},
{{'s', 't'}, {'u', 'v'}, {'w', 'x'}}
};
char (*pa)[2] = &a[1][0];
char (*ppa)[3][2] = &a[1];
//I tried out this one without much understanding.
printf("The letter r can be reached by pointer *pa is: %c\n", pa[4][3]);
//No error at compiling time, but did not print out the letter r.
printf("The letter r can be reached by pointer *ppa is: %c\n", ppa[4]);
return 0;
}
Thank you in advance!