Note:  Must see this post before reading the program’s explaination.  It will clear your doubts.
here is its link: https://jasleen7956.wordpress.com/2012/11/12/array-vs-pointer-array/

char *c[]={“ENTNG”,”NST”,”AMAZI”,”FIRBE”};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
void main()

Output of above program is  AMAZINGBEST


char *c[]={“ENTNG”,”NST”,”AMAZI”,”FIRBE”};
//initialise an array of pointers.
As already explained is a Two dimentional array pointer, where  c  points to c[0], which is again an array that store string “ENTNG”
Here,    *c[]  can be written as **c
c[0] = ENTNG
c[1] = NST
c[2] = AMAZI
c[3] = FIRBE
char **cp[]={c+3,c+2,c+1,c};
//initialise array of pointer to pointers
cp is a pointer variable pointing to c[3]
cp[0] -> c+3     i.e  FIBRE
cp[1] -> c+2     i.e  AMAZI
cp[2] -> c+1     i.e  NST
cp[3] -> c          i.e  ENTNG
char ***cpp=cp;
pointer to (pointer to pointer)
can be written as **cpp[] ,  cpp points to first element of cp[0]
cpp[0] -> cp[0]        FIRBE
cpp[1] -> cp[1]        AMAZI
cpp[2] -> cp[2]        NST
cpp[3] -> cp[3]        ENTNG
cpp points to cp[0]
|_c+3_|_c+2_|_c+1_|__c_|          cp
  cp[0]    cp[1]    cp2]     cp[3]
|_c+3_|     cpp     // cpp->cp[0]


++cpp ,  cpp is incremented,  now it points to cp[1]

|_c+3_|_c+2_|_c+1_|__c__|          cp
  cp[0]   cp[1]    cp[2]   cp[3]
|_c+2_|         cpp   //cpp->cp[1]
++cpp increments cpp as cpp+1
i.e cpp = &cp[0]
 and  after ++cpp,    cpp- >&cp[1]
for instance we can say: 
cp[0]    FIBRE
// we can’t say cpp[-1] == cp[0]  because negative index cause undefined behavior 😉
cpp[0] -> cp[1]     AMAZI
cpp[1] -> cp[2]      NST
cpp[2] -> cp[3]      ENTNG
++cpp -> cp[1]       // cp[1] -> c+2
++cpp = &cp[1]       // &(c+2)
*++cpp = *(&c+2)     //  c[2]
**++cpp = *&c[2]     // which is AMAZI
printf(“%s”,*–*++cpp + 3);
 ++cpp ->cp[2]   //   now, pointer points to cp[2] instead of cp[1]
for instance we can say:
cp[0]   FIBRE            //can’t say  here cpp[-2] ==cp[0]
cp[1]   AMAZI           //can’t say here cpp[-1] ==cp[1]
cpp[0] -> cp[2]     NST
cpp[1] -> cp[3]     ENTNG
cp[2] -> (c+1)   and   *cp[2] -> *(c+1)  
–*cp[2]=*&(c+1-1)   // c
*–*++cpp = *(&c[0])  // c[0]       ENTNG
 *–*++cpp = ENTNG        //c[0]
*–*++cpp  + 3  = c[0][3]   //row= 0  column =3   of pointer array  ‘c’
 i.e    NG
printf(“%s”,*cpp[-2]  + 3);
As   pointer  cpp -> cp[2]
cpp = &cp[2] 
*cpp = *&cp[2]    //  address of cp+2
*cpp[-2] = cp+2 – 2    // =  cp[0],   cp[0] is c+3
i.e    FIRBE
*cpp[-2]  = c[3][0]
*cpp[-2]  + 3  = c[3][3]        // row =3, column =3
i.e  BE
printf(“%s”,cpp[-1][-1]  + 1);
As   pointer  cpp -> cp[2]
cpp = &cp[2] 
cpp[-1] == &cp[2]) – 1  == (cp+2) -1  == cp[1] == c+2
cpp[-1][-1] == (c+2 ) -1 == c[1] == NST
cpp[-1][-1] +1  == ST
Hence its output is  AMAZINGBEST           🙂           🙂            🙂              🙂

5 thoughts on “Pointers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s