Pointer to array of pointer to string: A pointer to an array which contents are pointer to string.
Example of Pointer to array of pointer to string:
What will be output if you will execute following code?
#include<stdio.h>
Example of Pointer to array of pointer to string:
What will be output if you will execute following code?
#include<stdio.h>
int main(){
static char *s[3]={"math","phy","che"};
typedef char *( *ppp)[3];
static ppp p1=&s,p2=&s,p3=&s;
char * (*(*array[3]))[3]={&p1,&p2,&p3};
char * (*(*(*ptr)[3]))[3]=&array;
p2+=1;
p3+=2;
printf("%s",(***ptr[0])[2]);
return 0;
return 0;
}
Output: che
Here
ptr: is pointer to array of pointer to string.
P1, p2, p3: are pointers to array of string.
array[3]: is array which contain pointer to array of string.
Pictorial representation:
Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.
As we know p[i]=*(p+i)
(***ptr[0])[2]=(*(***ptr+0))[2]=(***ptr)[2]
=(***(&array))[2] //ptr=&array
=(**array)[2] //From rule *&p=p
=(**(&p1))[2] //array=&p1
=(*p1)[2]
=(*&s)[2] //p1=&s
=s[2]=”che”
Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
C tutorial
4 comments:
please tell me
how would u write
(*(***ptr+0))[2]=(***ptr)[2];
it should be (****ptr)[2];.......
what is static function
manu, i think since ptr contains only contains one pointer which points to address=800(as shown in fig) which is base address of array[],and so even if ptr[0]is replaced by ptr it will do the same.
but this doesn't holds good.
Post a Comment