Program of Array of Pointers and Pointer to Array

Program is:

 #include<stdio.h>
 char *c[]={"ENTNG","NST","AMAZI","FIRBE"};
 char **cp[]={c+3,c+2,c+1,c};
 char ***cpp=cp;
 void main()
 {
 printf("%s",**++cpp);
 printf("%s",*--*++cpp+3);
 printf("%s",*cpp[-2]+3);
 printf("%s",cpp[-1][-1]+1);
 }

Its answer is given AMAZINGBEST

Note:= Dont mingle array of pointers with Pointer to an array.
cpp+2 and cpp-2 are used as Second time incrementing or decrementing cpp.

 >  #include<stdio.h>
 > char *c[]={"ENTNG","NST","AMAZI","FIRBE"};
 c is Array of Pointers

 c[0] =ENTNG (Pointer to Array of Characters)
 c[1] =NST
 c[2] =AMAZI
 c[3] =FIRBE

 > char **cp[]={c+3,c+2,c+1,c};

 cp is Array of Pointer to Array of pointer
 cp[0]=c+3            *cp[0]=FIRBE
 cp[1]=c+2            *cp[1]=AMAZI
 cp[2]=c+1            *cp[2]=NST
 cp[3]=c              *cp[3]=ENTNG

 > char ***cpp=cp;

 cpp is pointer to Array of pointer to Array of Pointers
 cpp=&cp[0];                *cpp=cp[0]                **cpp=FIRBE
 ++cpp=&cp[1]              *++cpp=cp[1]               **++cpp=AMAZI
 cpp+2=&cp[2]               *cpp+2=cp[2]              **cpp+2=NST
 cpp+3=&cp[3]               *cpp+3=cp[3]               **cpp+3=ENTNG

 > void main()
 > {
 > printf("%s",**++cpp);
**++cpp=**&cp[1]=*cp[1]=AMAZI

 Now cpp is incremented, So cp has following values now:

 cpp=&cp[1]
 ++cpp=&cp[2]
 cpp+2=&cp[3]
 --cpp=&cp[0]

 To set up this:
 cpp=&cp[0]

 cp[-1]=c+3             *cp[-1]=FIRBE
 cp[0]=c+2              *cp[0]=AMAZI
 cp[1]=c+1               *cp[1]=NST
 cp[2]=c                   *cp[2]=ENTNG

 > printf("%s",*--*++cpp+3);

 *--*(&cp[1])+3
 *--cp[1]+3
 *(c+1-1)+3
 (*c)+3
 ENTNG+3
 (As ENTNG is Pointer to Array that points to E, on adding 3 It point to N)
 =NG

 cpp=&cp[2]
 ++cpp=&cp[3]
 --cpp=&cp[1]
 cpp-2=&cp[0]

 this means:
 cp[-2]=c+3      *cp[-2]=FIRBE
 cp[-1]=c+2      *cp[-1]=AMAZI
 cp[0]=c+1       *cp[0]=NST
 cp[1]=c         *cp[1]=ENTING

printf("%s",*cpp[-2]+3);
*(*(cpp-2))+3
 Now cpp is not an array so change to cp
 *(*(&cp[-2]))+3
 *(c+3)+3

 FIRBE+3=BE
 > printf("%s",cpp[-1][-1]+1);
*(*(cpp-1)-1)+1
 *(*(&cp[-1]))+1
*(cp[-1])+1
*(c+1)+1
NST+1
=ST

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Program of Array of Pointers and Pointer to Array

  1. click says:

    Wow, marvelous weblog layout! How lengthy have you
    been blogging for? you made blogging look easy. The full glance of your website is excellent, as neatly as the content material!

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