Program of Array of Pointers and Pointer to Array

Program is:

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

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);

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


 To set up this:

 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);

 (As ENTNG is Pointer to Array that points to E, on adding 3 It point to N)


 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

 Now cpp is not an array so change to cp

 > printf("%s",cpp[-1][-1]+1);

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: Logo

You are commenting using your 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