#include "d:\Practice Programs\Puzzle Feuer\Puzzles\defs.h" // SEE END OF THIS FILE FOR ARRAY DISCRIPTION. /* *c[] evaluates to a char, so c[] points to chars and c is an array of pointer-to-char. The elements of c have been initialized to point to the char arrays ENTER, NEW, POINT, and FIRST. */ char *c[] = { "ENTER", "NEW", "POINT", "FIRST" }; /* **cp[] evaluates to a char, *cp[] is a pointer-to-char, and cp[] is a pointer to pointer-to-char. Thus cp is an array of pointers to pointer-to-char. The elements cp have been initialized to point to the element of c. */ char **cp[] = { c+3, c+2, c+1, c }; /* ***cp evaluates to a char, **cp points to a char, *cp points to a pointer-to-char, and cp point to a pointer-to-pointer-to-char. */ char ***cpp = cp; void main() { printf("%s", **++cpp ); // *(*(++cpp)) Increment cpp then follow the pointers. printf("%s ", *--*++cpp+3 ); // (*(--(*(++cpp))))+3 Increment cpp, follow the pointer to cp[2], // decrement cp[2], follow the pointer to c[0], index 3 from // the addres in c[0]. printf("%s", *cpp[-2]+3 ); // Inderectly reference -2 from cpp yielding cp[0], follow the // pointer to c[3], index 3 from the address in c[3]. printf("%s\n", cpp[-1][-1]+1 ); // Indirectly reference -1 from cpp yielding cp[1], indirectly // reference -1 from cp[1] yielding c[1], index 1 from the addres // in c[1]. }// end main /* c has starting address of char array. c[i] has address of the i th member of the char array. c[2] "POINT" *c[i] has address of the first char if the i th member of the char array. *c[2] "P" cp has adds of pointers to members of the char array c. cp == add -> add -> "FIRST" cp[i] has add of i th member of c char array cp[1] == add -> add -> "POINT" *cp[i] de-reference cp[i] to the i th member of c char array. *cp[1] -> add -> "POINT" cpp has the add of cp which has add of first member of c char array. cpp -> add (cp) -> add -> c (first member of c) *cpp de-reference, points to same add as *cp, *cpp -> add (cp) -> c (first member of c char array.) **cpp double de-reference points to first member of c char array. **cpp -> c (first member of c char array.) ***cpp triple de-reference points to first char of c char array. ***cpp -> "E". cpp -> add -> add -> first char in c char array. *cpp (first de-reference or evaluation) treats the value in cpp as a pointer and fetches what is in that memory add. **cpp (second de-reference or evaluation) treats the value in cpp as a pointer, fetches what is in that memory add and then uses that data as a pointer to fetch the data at that memory add. ***cpp (therd third de-reference or evaluation) takes data in cpp treats it as a pointer, fetches data, treats that data as a pointer, fetches data and treats that data as pointer fetches data at that memory add. /* int a[3][3] = { {1, 2, 3 }, {4, 5, 6 }, {7, 8, 9 } }; Remember memory is just one long string of bits. When the program states int a[3][3] it is asking for a contiguous piece of that string that is 9 int (in this platform 32 bit) long. The array a[n][m] is C's way of using memory off set addressing to access member of that array. n*m tell how many array members, how meny memory locations to allocate. n = number of sub sections in the memory allocation, and m = number of members in that subsection. This is how *(*(a+n)+m) will give access to same array member as a[n][m]. *(a+n) gets to starting address of n subsection and *(subsection start)+m) gets to the m member in that subsection. pa is a pointer array of the subsections of the a int array. by using pointer indirection *(*(pa+n)+m) you can access the subsection members. So a[n][m] == *(*(pa+n)+m), but this does not convert to Do not make the mistake a[n][m] == *(*(a+n)+m) == *(*(pa+n)+m) != *p+n*m != *(p+n*m) As a[2][2] give access to the 8 th member of the array value 9. as *p+2*2 == *p+4 == a[1][1] the 4 th member of the array 5. With arrays the first member is the 0 th (zero th.) 1 ->a ->a[0] ->a[0][0] *p *pa 2 ->a[0][1] *(p+1) 3 ->a[0][2] *(p+2) 4 ->a[1] ->a[1][0] . *(pa+1) 5 ->a[1][1] *(*(pa+1)+1) 6 ->a[1][2] 7 ->a[2] ->a[2][0] *(pa+2) 8 ->a[2][1] . 9 ->a[2][2] *(p+8) *(*(pa+2)+2) Is in memory */